유효성 검사 오류가있을 때 내 사용자 지정 ComboBox의 여백을 설정하려고합니다. 나는 ErrorBorder 요소의 BorderBrush를 설정할 때WPF Validation.ErrorTemplate에 사용하는 ControlTemplate이 상위 컨트롤에 액세스 할 수 없습니다.
<ComboBox x:Class="Emsc.Prestige.Windows.AutoCompleteComboBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="MyComboBox">
<Validation.ErrorTemplate>
<ControlTemplate>
<Border x:Name="ErrorBorder" BorderThickness="2" CornerRadius="2">
<AdornerElementPlaceholder x:Name="adorner"/>
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=adorner, Converter={StaticResource ErrorContentToErrorTypeConverter}}"
Value="Critical">
<Setter TargetName="ErrorBorder" Property="BorderBrush" Value="Red" />
<Setter TargetName="MyComboBox" Property="Margin" Value="0,0,10,0" />
</DataTrigger>
</ControlTemplate>
</Validation.ErrorTemplate>
</ComboBox>
그래서, 그것은 잘 작동 : 여기 내가 사용하려고 코드입니다. 내가 XAML에서가 아니라 뒤에 코드에 따른 myComboBox의 여백으로 접근하고 싶습니다
The property 'TargetName' does not represent a valid target for the 'Setter' because an element named 'MyComboBox' was not found. Make sure that the target is declared before any Setters, Triggers or Conditions that use it.
: 내 따른 myComboBox의 여백 속성 (또는 속성)에 액세스하려고 할 때, 나는 다음과 같은 오류가 발생합니다. DataTrigger의 Setter를 통해 "TemplatedParent"에 액세스하는 방법이 있습니까?