简体   繁体   中英

style trigger on datagrid element name

I would like to set my styles inside the window.resources tag I need to set the maxlength property on a DatagridTextColumn but i cannot find a working solution.

The windows resource:

<Window.Resources>
    <Style x:Key="CellEditStyle" TargetType="{x:Type TextBox}">
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Style.Triggers>
            <DataTrigger Binding="{??? ElementName=RefFourn ???}">
                <Setter Property="MaxLength" Value="19"/>
            </DataTrigger>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

The xaml datagrid:

<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn x:Name="RefFourn" Header="Ref Fourn" EditingElementStyle="{StaticResource CellEditStyle}" Binding="{Binding Path=RefFourn, ValidatesOnDataErrors=True, NotifyOnValidationError=True}">
</Datagrid.Columns
</Datagrid>

Change your style as below:

  <Style x:Key="CellEditStyle" TargetType="{x:Type TextBox}">
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="MaxLength" Value="19"/>
        <Setter Property="Padding" Value="0"/>
        <Style.Triggers>               
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM