Within my Windows.Resources I have the following column defined:
<DataGridTextColumn x:Key="CustomColumn" x:Shared="False">
<DataGridTextColumn.Header>
<StackPanel>
<Label Padding="0" Name="labelA"/>
<Separator HorizontalAlignment="Stretch"/>
<Label Padding="0" Name="labelB"/>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
I have an event that gets fired from my ViewModel and adds the following "CustomColumn" to my DataGrid:
var column = FindResource("CustomColumn") as DataGridTextColumn;
var label = FindName("labelA") as Label;
label.Content = string.Format("A {0}", i);
DataGrid1.Columns.Add(column);
The question is, how would I change the content of the two labels inside the CustomColumn header? I above code fails because it is unable to find "labelA". (adding the column works, but I also need to set these labels). My guess is, I need to find it through the VisualTree -- but I want to make sure I'm not doing anything else wrong.
Thanks for the help.