1

My WPF project has a main window with a number of buttons and a frame. I display a page within the frame, and the buttons above use routed commands in order to call methods present in the page below. With me so far?

Everything works fine until I change the page. Even though this new page has methods which relate to the commands, it seems the routed commands are still looking for methods in the previous page. I don't know why this is happening when I've set the typeof() argument in the command itself:

public static RoutedCommand cmd = new RoutedCommand("Foo", typeof(BarPage));

How can I fix this? I've noticed that setting focus on a textbox in the newly-selected page will correct things, however this isn't a viable solution as the page will not always contain fields. I've also tried setting focus on the page itself but the problem still applies.

Thanks in advance.

Jonathan
  • 13,947
  • 17
  • 94
  • 123
  • Not sure if it would help, but you could try calling CommandManager.InvalidateRequerySuggested() after the new page loads. By default, the command manager only checks CanExecute for certain conditions. Maybe the page navigation doesn't trigger this properly. – NathanAW Jul 05 '11 at 15:26
  • Where do you define the handlers for CanExecute and Execute? – vrrathod Jul 05 '11 at 22:20
  • I've now sorted the issue - see my comment in the [marked answer](http://stackoverflow.com/questions/6584720/issue-when-using-routed-commands-with-a-frame/6589576#6589576) for more details. Thank you both very much for your help. – Jonathan Jul 06 '11 at 10:01

0 Answers0