tags:

views:

374

answers:

1

Hi,

I'm just starting to use the composite application libraries for WPF. In my shell I have a region in a tabcontrol that is used to display different types of views. I also have a toolbar with buttons hooked up to commands, for example save. The commands are bound in my views, and the views have the canExecute and execute methods.

The idea is that when i click a tab, my tool bar buttons should be enabled or disabled according to the methods in the view. Problem is when I switch tabs the view is not getting the focus and the canExecute for that view doesn't get called. The toolbar buttons remain connected to the commands in the previously selected view, and reminds that way until i actually click on the new view

I'm stumped right now on how to force the view to get the focus. I've tried looking at the tab's content when the tabs SelectionChanged and setting the focus there but its not making a difference. Any ideas?

A: 

Try listening for the View.Loaded event, then call View.focus() in the handler. Wpf will not accept focus requests before an element is initialized and loaded. Since the SelectionChanged event is raised before the view is loaded, the focus request will just be ignored. The loaded event is called each time the element is shown after being hidden.


See this blog post for more information on focus:

http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx

Robin