Context menu on WPF Datagrid fails to appear

Aug 26, 2009 at 12:23 PM

Hi,

 

    I'm trying to implement a filtering option on the WPF Datagrid control. Something like, if the user click on an arrow button on the column header he would be presented with a context menu from where he can choose the filtering options (A filter view would appear). 

 

   My problem now is the context menu (Filter view) works and appears when i implement it in a WPF Desktop application but the same code does not work in an XBAP applicaiton even with full trust. I then tried to debug it further by opening the Visual Studio Output window and it gave me the following error whenever i tried to show a context menu when I click on the datagrid column header.

 

 

A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in WindowsBase.dll
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=DropDown.IsOpen; DataItem='DropDownButton' (Name='PART_DropDown'); target element is 'DropDownButton' (Name='PART_DropDown'); target property is 'IsChecked' (type 'Nullable`1') Win32Exception:'System.ComponentModel.Win32Exception: Cannot create a top-level child window
   at MS.Win32.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
   at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
   at System.Windows.Interop.HwndSource..ctor(HwndSourceParameters parameters)
   at System.Windows.Controls.Primitives.Popup.PopupSecurityHelper.BuildWindow(Int32 x, Int32 y, Visual placementTarget, Boolean transparent, HwndSourceHook hook, AutoResizedEventHandler handler)
   at System.Windows.Controls.Primitives.Popup.BuildWindow(Visual targetVisual)
   at System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
   at System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.Controls.Primitives.Popup.CreateRootPopup(Popup popup, UIElement child)
   at System.Windows.Controls.ContextMenu.HookupParentPopup()
   at System.Windows.Controls.ContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
   at MS.Internal.Data.ClrBindingWorker.UpdateValue(Object value)
   at System.Windows.Data.BindingExpression.UpdateSource(Object value)'

A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in WindowsBase.dll

System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=DropDown.IsOpen; DataItem='DropDownButton' (Name='PART_DropDown'); target element is 'DropDownButton' (Name='PART_DropDown'); target property is 'IsChecked' (type 'Nullable`1') Win32Exception:'System.ComponentModel.Win32Exception: Cannot create a top-level child window

 

Can anybody help me here? 

 

Thanks,

ranjith