Code Relief .NET
Archive for April, 2011
WPF: DataContext for ContextMenu
Posted by Tim Valentine in Bug Patches, Controls, Customization, WPF on April 20, 2011
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
Attached Properties, C#, ContextMenu, Controls, Style, Styles, WPF, XAML
-
You are currently browsing the archives for April, 2011
Categories
- General (5)
- VSTO (1)
- WPF (12)
- Controls (5)
- Bug Patches (2)
- Customization (4)
- Controls (5)
Tags
Animation Arrays Attached Properties Button C# Casting Code Generation COM ContextMenu Controls DataGrid DataGridColumn DataGridColumnHeader Dynamic Dynamic Classes Exception Frame-based Hashtable Hide ListBox ListBoxItem ListView ListViewItem Maximize MenuItem MessageBar Minimize Run-time SelectAllCommand Selector Show SplitButton Style Styles VSTO Window WindowCustomizer WindowHelper Windows Forms WinForms WPF XAMLArchives
- March 2012 (2)
- November 2011 (1)
- August 2011 (1)
- April 2011 (1)
- January 2011 (3)
- April 2010 (1)
- March 2010 (1)
- February 2010 (1)
- July 2009 (2)
- June 2009 (4)
- May 2009 (1)