2

I would like to show my user control inside row details.

I have a complex data structure and cant show all items(just a few) inside datagrid, so I would like to open another control and show it inside row details. I had previously created(designed) it. I'm not creating it dynamicaly.

Is there any way how to achieve it?

I am working with C# and WPF and developing desktop app.

I would like to be able to use it like:

    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
        //    <StackPanel Orientation="Horizontal" Margin="20,0,0,0">
        //        <TextBlock Text="Category:" FontWeight="Bold"/>
        //        <ComboBox IsEditable="True" 
        //                  ItemsSource="{Binding Source={x:Static Data:CheckBook.Categories}}" 
        //                 Text="{Binding Category}" />
        //     </StackPanel>
        <MyControl ItemsSource="blabla">
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>  
TheBoyan
  • 6,802
  • 3
  • 45
  • 61
Martin Ch
  • 1,337
  • 4
  • 21
  • 42

2 Answers2

0

It sounds like you're describing a hierarchical data structure. (Data with parent/child or master/detail relationships)

Microsoft offers guidance on displaying Hierarchical Data in WPF in their Data Templating Overview Specifically, this is covered here.

David
  • 72,686
  • 18
  • 132
  • 173
0

the simplest way to achieve that is to use the following:

Please note, if all you need is one columns with your user/custom control, it'd probably make more sense to use smth. like ListBox with a customized ItemTemplate, as it's much lighter.

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DataGrid>
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            **...your user control goes here**
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>