DataTemplate for floating ToolWindow is not being picked up

I just noticed this bug when I was looking to replicate another bug outside of our application.

If you add a new ToolWindow where it is set to float when you are using a DataTemplate to display the view based on a ViewModel type it won't pick it up. Although it will work if docked initially. However it does work by using a TemplateSelector like in your MVVM ToolWindow example.

I managed to replicate this using your MVVM ToolWindows example.

I modified the MainView.xaml to not use the TemplateSelector and use DataTemplates, and then in the MainViewModel I just created an instance of a new ToolWindow but set it to float.

Comments (3)

This could possibly be a scope issue. Keep in mind that when you define the DataTemplate in the main Window's Resources or at a level lower than that, only docking windows within that hierarchy can ever pick it up. Floating docking windows are hosted in a separate WPF Window behind the scenes and thus won't inherit those resources. If you define them in the Application.Resources instead, they should get applied to all Windows in your ap.

Cheers for that. It does work if you put it in the Application.Resources will make a note of that my end.

Now on to the issue I have, bit of a weird one.

Essentially a TabControl within my ToolWindow changes its selection the second time of getting focus.

This can be replication by modiying your MVVM ToolWindows example.

I modified ToolItem1ViewModel to have a TabControlSelectedIndex property and the ToolItem1View.xaml to have a TabControl which is bound to my previously added property. When I select that ToolWindow for a second time I can see that the tab selection has gone from All to High (0 to 1).

Thanks for the sample. After debugging, it appears our logic that tries to focus a focusable child control in the tool window is what triggers this. We basically recurse down the visual tree and look for a focusable descendant visual of the tool window. But for whatever reason, the WPF TabControl's TabPanel is listing the "High" tab first in this scenario. So we find that before the "All" tab and thus end up focusing the "High" tab, thereby selecting it.

I'm not sure why the WPF TabControl is returning them in that order. But one workaround would be to add focusable content within each tab. Any element should work, as long as it is visible and has Focusable set to true. Then it should focus that content instead of ever falling back to looking at the tabs.

Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 10 days ago,
which was after the last post in this thread.