Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: Patch available: Automatically call RaiseCanExecuteChanged() when CommandParameter changes

$
0
0
GOstrowsky wrote:
I am afraid I don't completely understand the scenario where you are experiencing this issue. The items list that are shown in the grid, would they be the names of different Views to navigate to?
It would be helpful if you describe us the behaviour you are trying to accomplish. Also, you could send us a code sample of your app so we could reproduce and debug the issue to provide you better support.
I actually hit this again the other day (when I was working in a new codebase without my workaround). My scenario was this:
  • There is a TextBox on a form
  • The TextBox has a custom ContextMenu, with an extra MenuItem of the form "Copy Special"
  • The "Copy Special" command must be disabled unless the text displayed in the TextBox (not just the bound value) is "valid"
My first attempt was to bind the Command property of the MenuItem to a DelegateCommand exposed by the VM, and bind the CommandParameter to the Text property of the TextBox. This does not work as the CanExecute handler doesn't get called by WPF when the CommandParameter changes; the MenuItem stays in the same state forever, depending on the validity of the text the first time the context menu is opened.

This wasn't too hard to work-around, as I only had one property to worry about, but imagine I was using the same Command & CommandParameter binding in a DataTemplate.
Please notice that this discussion thread is related to Prism v1, which is not available anymore (The current version since February 2012 is Prism v4.1). Therefore, I would suggest you to open a new discussion in order to mantain and motivate a clean and ordered forum, unless your issue directly relates to the one discussed above.
AFAICT there would be no difference in behaviour between Prism v1 & v4.1 here (although I've not tested). I can't see anything in the code that has changed. Starting a new thread seems a bit pointless, as that would actually hide the fact that I posted a workaround.

Viewing all articles
Browse latest Browse all 1878

Latest Images

Trending Articles



Latest Images