Archive for category Bug Patches

WPF: Access Keys Scoping

Problem

Within the WPF framework access keys are always scoped to the active window, regardless of what settings you may have set. This can cause problems when multiple elements exist within the window hierarchy. The WPF framework will likely choose the incorrect target element. What you need is to scope the access keys to the currently focused element, and unfortunately the WPF framework contains a internal bug that prevents this functionality.

Solution

Read the rest of this entry »

, , , , , , , ,

2 Comments

WPF: IsSynchronizedWithCurrentItem and ICollectionView Cancel Bug

Problem

As some of you may have noticed while working with a Selector-derived control and an ICollectionView, there is a bug with the IsSynchronizedWithCurrentItem property of Selector.  IsSynchronizedWithCurrentItem is provided by Selector to support the ability to keep its SelectedItem in-sync with the CurrentItem of its ItemSource’s ICollectionView. IsSynchronizedWithCurrentItem works perfectly except for one specific case: when the CurrentChanging event of ICollectionView is handled and the item change is cancelled.

In this case the Selector does not respect the cancel and it gets out-of-sync with the ICollectionView. I’d imagine this bug exists because the Selector class was likely implemented before ICollectionView, and Selector was not updated to match the addition. Whatever happened though the bug does exist in WPF 4.0 and can be very problematic. Luckily, with attached properties at our disposable we can work up an easy fix.

Solution

Read the rest of this entry »

, , , ,

11 Comments

WPF: DataContext for ContextMenu

Problem

Often times WPF  developers want to throw their computer out the window because of a small and very irritating truth about the ContextMenu control. I’m talking about the fact that ContextMenu is not in the same visual tree as its containing parent, resulting in many data binding issues. Since the ContextMenu is not in the same visual tree, ElementName, RelativeSouce (FindAncestor), etc bindings will not work. You can get around this through the use of the PlacementTarget property and some complex DataContext re-routing, but it is a pain, confusing, and does not scale well (at all). I will present a very simple attached property that relieves the situation.

Solution

Read the rest of this entry »

, , , , , , ,

8 Comments