mahboub_mo
mahboub_mo

Reputation: 3038

how to bind the Tag Properties of the textbox that placed in the DataGridColumnHeadertemplate to DataGridTextColumn.Name?

i have a textBox(txtSearch) placed in a DataGridColumnHeadertemplate like this:

 <UserControl.Resources>
 <Style x:Key="DataGridColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                        <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Text="{TemplateBinding Content}" HorizontalAlignment="Center" />
                            <Grid Grid.Row="1" >
                            <TextBox x:Name="txtSearch" Tag="{Binding DataGridTextColumn.Name, ElementName=grd}"  Text="" HorizontalAlignment="Stretch"  BorderThickness="1" TextChanged="TextBox_TextChanged" />
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

and use it for a datagrid like this:

 <DataGrid x:Name="grd" ItemsSource="{Binding Source={StaticResource theSource}}" AutoGenerateColumns="False"  ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}">
        <DataGrid.Columns >
            <DataGridTextColumn Header="نام" Binding="{Binding Title}" x:Name="Title" ></DataGridTextColumn>
            <DataGridTextColumn Header="ID" Binding="{Binding ParentID}" x:Name="ParentID"></DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>

and now i need to bind the txtSearch Tag properties to DataGridTextColumn.Name.how can i do that?

Upvotes: 0

Views: 1503

Answers (1)

Nikolay
Nikolay

Reputation: 3828

You can try to use RelativeSource with Mode=FindAncestor (http://msdn.microsoft.com/ru-ru/library/dd553635(v=vs.95).aspx)

Upvotes: 1

Related Questions