0

我正在尝试手动触发 c# 代码中的 setter 属性,但是我不确定这是否可能?

C#;

// apply this setter to the control    
myControl.FindResource("StandardTextBoxStyle") as Style;
// how can I trigger ErrorTemplateSetter from here!?

我的风格;

<Style TargetType="{x:Type TextBox}" x:Key="StandardTextBoxStyle">
    <Setter Property="VerticalAlignment" Value="Center" />
    <Setter Property="Validation.ErrorTemplate" x:Name="ErrorTemplateSetter">
        <Setter.Value>
            <ControlTemplate>
                <DockPanel LastChildFill="true">
                    <Border Background="OrangeRed" DockPanel.Dock="right" Margin="5,0,0,0" 
                            Width="20" Height="20" CornerRadius="5"
                            ToolTip="{Binding ElementName=customAdorner, 
                                      Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                        <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" 
                               FontWeight="Bold" Foreground="white" />
                    </Border>
                    <AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center" >
                        <Border BorderBrush="red" BorderThickness="1" />
                    </AdornedElementPlaceholder>
                </DockPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
4

0 回答 0