"선택"되었을 때 DataTrigger를 사용하여 시각적으로 UserControl을 변경하는 데 문제가 있습니다.
"IsSelected"라는 클래스에서 'bool'종속성 속성을 만들었습니다.
UserControl 종속성 속성에 대한 DataTrigger 바인딩
나는이 XAML 사용하고 있습니다 :
<UserControl x:Name="zControl"
x:Class="Intel.AdaptivePerformance.Client.UI.Controls.ZoomControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignWidth="50" d:DesignHeight="32">
<Border BorderBrush="Black" BorderThickness="1,0,1,2" Background="#2F000000">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=zControl, Path=IsSelected}" Value="True">
<Setter Property="BorderThickness" Value="1,0,1,0" />
<Setter Property="Background" Value="{x:Null}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Label Content="{Binding ElementName=zControl, Mode=OneWay, Path=Text}" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center" />
</Border>
</UserControl>
을 그리고이 C#을 사용하여 다음 레이블의 Content 속성에 바인딩하기 때문에
public partial class ZoomControl : UserControl {
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(ZoomControl), new PropertyMetadata(false));
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ZoomControl), new PropertyMetadata(null));
public ZoomControl() {
InitializeComponent();
}
public bool IsSelected {
get {
return (bool) GetValue(IsSelectedProperty);
}
set {
SetValue(IsSelectedProperty, value);
}
}
public string Text {
get {
return (string) GetValue(TextProperty);
}
set {
SetValue(TextProperty, value);
}
}
}
그것은 이상한 작동하고 있지만하여 DataTrigger 바인딩은 아니다 트리거링. DataTrigger 바인딩에 Mode = OneWay를 추가하려고 시도했지만 차이를 만들지 않습니다.
편집 :
나는 다른 setter 속성 "여백"을 추가하고 속성을했다.
그래서 어떤 이유로 Setters는 Border의 기존 속성을 무시할 수 없습니다. 왜 그런지 알아?