我什么时候应该选择Style.Triggers时,我应该选择ControlTemplate.Triggers?使用一个在另一个上有什么好处吗?
假设我有这些样式可以达到相同的效果:
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ControlTemplate.Triggers>
...
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
...
</Setter>
<Style.Triggers>
...
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud) 我有2个ComboBoxes,其ItemsSource被绑定到相同的ObservableCollection:
public ObservableCollection<MyType> MyTypeCollection { get; set; }
Run Code Online (Sandbox Code Playgroud)
我已经定义了2个不同的SelectedItem属性,这些属性又被绑定到正确的属性ComboBox.
public MyType MySelectedItem1 { get; set; }
public MyType MySelectedItem2 { get; set; }
Run Code Online (Sandbox Code Playgroud)
每当我在其中一个中选择一个项目时,我班级中定义的ComboBoxes两个SelectedItem属性都被设置为该选择.两者ComboBoxes也在视觉上设置为该值.
为什么是这样?
我尝试了几样的东西Mode=OneWay,但它没有用.
这是我的XAML(为问题修剪):
<ComboBox SelectedItem="{Binding MySelectedItem1}"
ItemsSource="{Binding MyTypeCollection, Mode=OneWay}"/>
<ComboBox SelectedItem="{Binding MySelectedItem2}"
ItemsSource="{Binding MyTypeCollection, Mode=OneWay}"/>
Run Code Online (Sandbox Code Playgroud) 在 WPF 中,可以绑定到静态属性。现在我知道两种方法:
Content="{x:Static stat:Statics.CurrentUser}"
Run Code Online (Sandbox Code Playgroud)
或者:
Content="{Binding Source={x:Static stat:Statics.CurrentUser}}"
Run Code Online (Sandbox Code Playgroud)
这两种方法有什么区别吗?