0
votes

I've been stumped with this problem for a couple weeks and I'm hoping I can get some suggestions. I have 2 Prism regions. A Toolbar region which contains a ToolbarView (ToolBarTray control) and a content region that contains a DataGridView (DataGrid control).

regions

My toolbar region has various RoutedCommands that perform commands on the DataGrid

<ToolBar ClipToBounds="False">
    <Button Command="{x:Static ApplicationCommands.Undo}"
            Content="Undo"/>
    <Button Command="{x:Static ApplicationCommands.Redo}"
            Content="Redo"/>
    <Button Command="{x:Static local:CustomDataGrid.FooCommand}"
            Content="Foo"/>
</ToolBar>

When my DataGrid doesn't have keyboard focus, Undo, Redo and Foo buttons will disable. When I click on the a DataGrid cell, they will re-enable. Having these buttons disable when the DataGrid loses keyboard focus can be confusing and sometimes frustrating. (Example: Deleting a row makes the DataGrid lose keyboard focus which disables all the buttons). Is there anything I can do to ensure that Undo/Redo and Foo will stay enabled and will work on the DataGrid? I've considered using IEventAggregator but I feel like that defeats the purpose of using RoutedCommands. Any suggestions would be appreciated.

1

1 Answers

0
votes

I've considered using IEventAggregator but I feel like that defeats the purpose of using RoutedCommands.

Exactly, and that's a good thing. Right now, how do your tests look for this setup? I reckon, there aren't any. If the tool bar's view model communicated with the data grid's view model through some code (as opposed to xaml, it can be IEventAggregator or some other service, or they could be the same instance), it would be lot easier to write a test suite.

My advice is to dump the routed commands.