DataGridTemplateColumn Header Binding

I have a dynamically created DataGrid with the following XAML:

 <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Cells}" IsReadOnly="True" Visibility="{Binding VisibilityStatus}"       
                                  CanUserResizeColumns="False" CanUserAddRows="False" RowBackground="{Binding Color}" Margin="0" RowHeight="25" HeadersVisibility="All">
                                <DataGrid.Columns>
                                    <DataGridTemplateColumn Header="{Binding Path=Header}"> 
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <ComboBox ItemsSource="{Binding UniqueValuesToLapMapping.Keys, UpdateSourceTrigger=PropertyChanged}" 
                                                          SelectedItem="{Binding SelectedValue, Mode=TwoWay}"
                                                          SelectedIndex="0" Width="55"
                                                          Background="{Binding Color}"/>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                </DataGrid.Columns>
                            </DataGrid>

The table is displayed correctly with all content except the title. No matter what class I put the title property in, I cannot bind to it. I tried putting it in the ViewModel, putting it in a class with the "Cells" property and putting it in a class that has all the properties that I am communicating with in the ComboBox. I also tried binding without "Path =" and set UpdateSourceTrigger to OnPropertyChanged and changed the value of the property at runtime: nothing works. What am I missing here?

This is a property that I associate with what I applied in all of these classes:

    private string _header = "TEST";
    public string Header
    {
        get { return _header; }
        set { SetField(ref _header, value, "Header"); }
    }
+4

Source: https://habr.com/ru/post/1543945/


All Articles