0

How to Access control inside datagrid ColumnHeaderStyle?

in this sample:

   <Style x:Key="DataGridColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Grid Name="grdPeresenter" VerticalAlignment="Center" HorizontalAlignment="Stretch">
                       <TextBox x:Name="txtSearch" Grid.Row="1" BorderThickness="2"  PreviewMouseLeftButtonUp="grid1_PreviewMouseLeftButtonUp"  HorizontalAlignment="Stretch" TextChanged="TextBox_TextChanged" >
                           </TextBox>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

and

    <DataGrid x:Name="grd" ItemsSource="{Binding Source={StaticResource theSource}}" AutoGenerateColumns="False"  
              ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}"  PreviewKeyDown="grd_PreviewKeyDown"
              SelectedIndex="{Binding SelectedIndex}"
              SelectedItem="{Binding SelectedItem}"
              behavior:MouseDoubleClick.Command="{Binding MouseDoubleClickCommand}" 
              GridLinesVisibility="Vertical">
    </DataGrid>

i want to access for example to textSearch of first Column of datagrid.is it possible?how?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
mahboub_mo
  • 2,908
  • 6
  • 32
  • 72

1 Answers1

1

According to this answer :

 var res = FindVisualChildren<TextBox>(grd).Where(t => t.Name == "txtSearch");

here yo can find all "txtSearch" headers textBox.

I'm sure it can get more direct way, but until then ..

Community
  • 1
  • 1
Harry
  • 1,686
  • 2
  • 15
  • 21