所以,我正在构建一个具有不同用户帐户的订单跟踪应用程序,其中一些人比其他帐户更少知道。这意味着某些帐户显示了某些控件,并为其他帐户隐藏。
窗口的数据台面设置为我的订单类,并且文本字段中的数据绑定在显示特定顺序的属性方面非常有效。但是,我制作的数据模板和触发器似乎根本没有做任何事情,我不确定为什么。我已经浏览了网络,我似乎找不到为什么它不起作用。这是XAML:
<Label Name="StatusLabelText" Content="Status:" FontSize="15" DockPanel.Dock="Top">
<Label.Resources>
<DataTemplate DataType="x:Type local:Order">
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=selectedAccount}" Value="Color Correct">
<Setter Property="Visibility" Value="Hidden"></Setter>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Label.Resources>
</Label>
我怀疑您要 hide label
,以防selectedAccount
值是Color Correct
。
如果我的假设是正确的,则需要进行此操作,而不是模板,这可以这样做:
<Label Name="StatusLabelText" Content="Status:" FontSize="15"
DockPanel.Dock="Top">
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=selectedAccount}"
Value="Color Correct">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
在旁注上,您应该使用Collapsed
而不是Hidden
来设置控制的可见性,以防即使在GUI上看不到标签,也不希望标签尺寸。在此处阅读有关它的更多信息。