using context menu (PopupMenu) with DataGrid's selected item!

Sep 18, 2010 at 7:03 PM
Edited Sep 19, 2010 at 1:32 PM

Hello Sir,

W.R.T creating popupmenu dynamically .http://sl4popupmenu.codeplex.com/

i am binding IsEnabledProperty  like this ,

var pm = new PopupMenu();
pm.AddItem("Accept Chat", delegate { AcceptChat(); });
AcceptChatBtnBinding = new Binding() { ElementName = "SessionsDG", Path = new PropertyPath("ItemsSource"), Converter = new ButtonsEnablityConvertor(), ConverterParameter = "AcceptNextChatBtn" };
pm.PopupMenuItem(0).SetBinding(Control.IsEnabledProperty, AcceptChatBtnBinding);

but an excpetion is occuring here are the details

Message = Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

StackTrace =

  at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.DependencyProperty_GetDefaultValue(DependencyProperty dp, DependencyObject propertyOwner, UInt32 propertyOwnerTypeId)
   at System.Windows.CoreDependencyProperty.GetDefaultValue(DependencyObject propertyOwner)
   at System.Windows.Data.BindingExpression.GetValue(DependencyObject d, DependencyProperty dp)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
   at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, Binding binding)
   at V3COC.Views.Home.GenerateMenu()

anyclue on whats going on.

OR how do i enable/disable popupmeuitem based on the value of the field ( Say "State") of the DataGrid's SelectedItem ?

 

Coordinator
Sep 19, 2010 at 4:14 PM
Edited Sep 19, 2010 at 11:02 PM

Sorry but I haven't yet implemented the IsEnabledProperty in the PopupMenuItem but will certainly do so within the week. So stay tuned...

Meanwhile you can easily fix it yourself by adding the following lines of code to the PopupMenuItem class:

public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register("IsEnabled"typeof(bool), typeof(PopupMenuItem), new PropertyMetadata(OnEnabledChanged));
public bool IsEnabled
{
get { return (bool)GetValue(IsEnabledProperty); }
 set { SetValue(IsEnabledProperty, value); }
}

And this is how you would use it:

pm.PopupMenuItem(0).SetBinding(PopupMenuItem.IsEnabledProperty, AcceptChatBtnBinding);

 

One workaround that does not require fiddling with the source code is to set the IsEnabled property in the Showing or Opening event(see Demo2).



 

Sep 19, 2010 at 10:11 PM
Edited Sep 20, 2010 at 1:04 AM

thank you sir ,

now i can set the IsEnable Property , but it's not disabling it . even when i set it in this way(without using binding)

pm.PopupMenuItem(0).IsEnabled = false;

even visiblity is not working

pm.PopupMenuItem(0).IsVisible = false;

thanks

Jamal.

P.S:

how much time did it took you to write these controls?

Coordinator
Sep 20, 2010 at 3:07 PM
Edited Sep 20, 2010 at 3:45 PM

Please try running your code again with the latest change set here:

http://sl4popupmenu.codeplex.com/SourceControl/list/changesets

Hopefully this will fix all issues you've encountered before.

Sep 21, 2010 at 5:28 AM

Working now ,

thanks & GOD bless you.

 

P.S

i asked earliar , how much time did it took to write these controls .

Coordinator
Sep 22, 2010 at 5:01 PM

I havent't kept track of the time I spent on it because i'm doing it on a hobby basis.

But as a rough estimation I can tell you that i've spent most of my free time on it, which very roughly averages to 20hours a week, and since I've been on it for nearly 6 months now I can conclude that it cost me around 500 hours of work(and fun also). Thats is definitely much more time than I expected when I first started it!

Sep 23, 2010 at 3:00 PM
Edited Sep 23, 2010 at 7:51 PM

I must admit , that it was a big big contribution to my project . and yes , other open source main menu control and context menu controls are much less in quality and functionality.

thank you so much.

May GOD bless you for the help you offered to us.

P.S

out of curiosity, one last personal question  , where are you from ?  which country?if you dont want to disclose it here , you can email me @ muhammad.jamal.shaikh@hotmail.com

Coordinator
Nov 5, 2010 at 6:39 PM

Thanks for showing your appreciation Jamal.

No worries, there is nothing top secret about where I live. I'm from Mauritius, a small island in the Indian Ocean. There's not much happening here but its a nice place to live.

Nov 7, 2010 at 2:23 PM

ok tc.

byte.