对于一个UserControl
我声明了一个DependencyProperty
:
public static readonly DependencyProperty DeselectedPresentationModeProperty =
DependencyProperty.Register(
"DeselectedPresentationMode",
typeof(int),
typeof(MyUserControl),
new FrameworkPropertyMetadata(1,FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty SelectedPresentationModeProperty =
DependencyProperty.Register(
"SelectedPresentationMode",
typeof(int),
typeof(MyUserControl),
new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
现在我想在 MultiTrigger 中使用这些属性:
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="MyUserControlItemStyle">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="gui:MyUserControl.DeselectedPresentationMode" Value="0" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="ContentTemplate" Value="{StaticResource PresentationModeIconOnly}" />
</MultiTrigger.Setters>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="gui:MyUserControl.DeselectedPresentationMode" Value="1" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="ContentTemplate" Value="{StaticResource PresentationModeSimple}" />
</MultiTrigger.Setters>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="gui:MyUserControl.SelectedPresentationMode" Value="0" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="ContentTemplate" Value="{StaticResource PresentationModeExtended}" />
</MultiTrigger.Setters>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="gui:MyUserControl.SelectedPresentationMode" Value="1" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="ContentTemplate" Value="{StaticResource PresentationModeIconOnly}" />
</MultiTrigger.Setters>
</MultiTrigger>
</Style.Triggers>
</Style>
...
...
<ListBox ... ItemContainerStyle="{StaticResource MyUserControlItemStyle}"/>
但是,如果我使用 MyUserControl 另一个项目,如果我更改我的DependencyProperty
. 我是否使用xaml
例如:
<Window
...
x:Class="WpfControlsTester.MainWindow"
Title="MainWindow">
<Grid>
<GUI:MyUserControl Name="test"/>
<Slider Minimum="0" Maximum="1" Value="{Binding SelectedPresentationMode, ElementName=test}" />
<Slider Minimum="0" Maximum="1" Value="{Binding DeselectedPresentationMode, ElementName=test}" />
</Grid>
或者,如果我使用任何类型的操作,例如 this.test.DeselectedPresentationMode = 0;
在事件或其他事情上的值。
我使用 WPF Inspector 来“调试”我的触发器,并且这两个属性始终具有其默认值 (1)。我的错误在哪里或者我应该添加什么来更新我的触发器?
编辑:将错误的“MyControl”更改为“MyUserControl”