WPF/Silverlight Tip: Transparent Hit Testing

February 23, 2012

Hit testing is the process of finding out which elements (if any) contain a certain point (typically the location of the mouse pointer). Sometimes, however, there is a need to disregard some elements in a hit testing scenario. Consider this simple program that allows moving of circles: One can grab a circle and drag it around. Here’s the MouseLeftButtonDown event handler on the containing Canvas: void OnMouseDown(object sender, MouseButtonEventArgs e) {     var shape = e.Source as Shape;     if(shape != null) {         _canvas.CaptureMouse();         _moving = true;         _current = e.GetPosition(_canvas);         _currentShape = (FrameworkElement)shape.Parent;     } } ...
no comments

Open days at John Bryce Hi-Tech

February 18, 2012

John Bryce Hi-Tech is having 4 Open days (half days) on current and upcoming technologies (held at John Bryce offices in Tel Aviv). Here’s the official poster: These open days are free of charge – but you must register (links in the next section): My first session (on the 29th of this month) is an overview of Windows Azure – from a developer perspective. What is it, where to get the tools, how to get started, the web and worker roles, storage, communications and more. If you heard about Azure, but did not yet take the time to...

Towers of Hanoi–WPF Style (Part 2)

February 13, 2012

In the first part, we saw how to recursively solve the Towers of Hanoi problem in C#. In this post I want to show a graphic view of the solution. This is a starting position with 7 discs: This is how it looks when the problem is solved: In between, the discs move with animation from pole to pole, as the solution dictates. Options include speeding up the process (with the slider, very useful), pausing the animation and resetting to the initial state. Here’s something in the middle: The Poles The poles are built as thick...

Towers of Hanoi–WPF Style (part 1)

February 11, 2012

I remember many years ago (at least 15), I was learning Prolog. I used the “Turbo Prolog” package from (what was once) Borland. One of the nice examples there was a solution of the Towers of Hanoi, with a simple animation that showed the steps graphically. This was all textual graphics (today’s Console windows), but it was impressive (at least it impressed me). Prolog was used to show off its AI capabilities, which are, in fact, a recursive, backtracking engine. No matter; we can do it in C#. Towers of Hanoi The story of the Towers originate from an...

A UniformGrid for Silverlight/Windows Phone

February 7, 2012

The UniformGrid panel in WPF has some useful features, especially as an items panel in an ItemsControl. I blogged about the usefulness of the UniformGrid here. But what about Silverlight? It has no UniformGrid, but we can create one as a custom panel. This would be usable in Silverlight for the desktop and for Windows Phone, and would be a simple enough example to show in one post. The layout process In WPF/Silverlight, layout is a two step process. The first step is Measure: the panel asks each child it’s hosting what size it would like to be, given...

A New Android Game in Town (by my brother)

February 5, 2012

Anyone who has ever written a game knows it’s hard to get it done from start to finish. Sure, I can put on a demo of some game I’ve created in several hours. But creating all the graphics, sound, animation, levels, transitions, scoring, etc, from start to finish is quite a challenge, especially for a single developer. That’s why I’m very proud of my young brother, Yaniv, that has worked hard for the past 10 months (while maintaining a proper day job!) on an awesome  fun game called Micro Wars, targeted for the Android platform. This game plays especially...

Next Windows Devices User Group Meeting

The second meeting of the Windows Devices User Group will be held on February 28th, at 17:00, Microsoft Offices in Ra’anana. The registration link and detailed agenda is here: http://windowsphonenavandlifecycle.eventbrite.com/ In this meeting we’ll talk about page navigation and the application lifecycle, which got a bit more complicated (but performs better) in the “Mango” release. We’ll also hear a “real life story” of porting an application to Windows Phone. See you there!