Hi,
I am in the process of converting a WinForms app to Silverlight.
We have a context menu currently on our grids, in the opening event I'd like to do a WCF call and enable/disable menu items based on what is returned.
Given the async nature of WCF calls, how do I prevent the menu displaying until this has been done?
Thanks,
Dan
You could cancel the opening event, which would prevent the menu from opening and then in your callback call for the menu to show then.
But you might also want to consider allowing the menu to open on the Opening but have all the questionable options in the menu already disabled and enable them on your call back. Even if they are all initially disabled, the end use would see that the menu is popped up on their action.
The second option is what I ended up implementing, however to allow this to work with command binding required quite a lot more work.
I ended up creating my own menu/menu item classes, inheriting from the Infragistics ones. I also created an IActionCommand interface which works like ICommand but CanExecute takes an Action(of Boolean) instead of returning boolean.
In the Opening event I can then disable each item and send a call to the CanExecute method, if it returns true the menu item is then enabled.
Nice solution which preserves the XAML and removes the need for any code-behind