Search code examples
wpfdatatemplatewpfdatagriddatatrigger

How do I have alternative content in a DataGrid.RowHeaderTemplate?


In a DataGrid, I'm using the RowDetails area to load a UserControl with its own ViewModel - works very well.

            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <vw:IndicesView DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
                                Path=DataContext.DrillDownIndexVM}" />
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>

I now want to use alternative UserControls, depending on a property in the main ViewModel.

How can this be done? Is the answer?


Solution

  • Check out WPF datatemplate selector http://www.switchonthecode.com/tutorials/wpf-tutorial-how-to-use-a-datatemplateselector