我想设置必填字段背景为红色,其他为绿色。所以我尝试在下面实现。但我无法使用触发器控制ValueConstraint Nullable属性。你能帮忙吗?
<Window x:Class="TriggerGirilmesigerekenalanlar.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:y="http://infragistics.com/Editors"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style TargetType="{x:Type y:XamTextEditor}">
<Style.Triggers>
<Trigger Property="ValueConstraint" Value="{x:Null}">
<Trigger.Setters>
<Setter Property="Background" Value="green"></Setter>
</Trigger.Setters>
</Trigger>
<Trigger Property="y:ValueConstraint.Nullable" Value="false">
<Trigger.Setters>
<Setter Property="Background" Value="red"></Setter>
</Trigger.Setters>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<y:XamTextEditor>
<y:XamTextEditor.ValueConstraint>
<y:ValueConstraint Nullable="False" ></y:ValueConstraint>
</y:XamTextEditor.ValueConstraint>
</y:XamTextEditor>
<y:XamTextEditor></y:XamTextEditor>
</StackPanel>
</Window>
实际上它会给出错误。
错误1无法解析样式属性'Nullable'。验证拥有类型是Style的TargetType,还是使用Class.Property语法指定Property。第15行位置26. D:\ Deneme proje \ TriggerGirilmesigerekenalanlar \ Window1.xaml 15 26 TriggerGirilmesigerekenalanlar
答案 0 :(得分:0)
试试这个:
<Style.Triggers>
<Trigger Property="ValueConstraint.Nullable" Value="{x:Null}">
<Trigger.Setters>
<Setter Property="Background" Value="Green"></Setter>
</Trigger.Setters>
</Trigger>
<Trigger Property="ValueConstraint.Nullable" Value="false">
<Trigger.Setters>
<Setter Property="Background" Value="Red"></Setter>
</Trigger.Setters>
</Trigger>
</Style.Triggers>
答案 1 :(得分:0)
这就是答案。
<Style TargetType="{x:Type y:XamTextEditor}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=ValueConstraint.Nullable, RelativeSource={RelativeSource Self}}" Value="false" />
<Condition Binding="{Binding Path=IsReadOnly, RelativeSource={RelativeSource Self}}" Value="false" />
<Condition Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}}" Value="true" />
<Condition Binding="{Binding Path=Visibility, RelativeSource={RelativeSource Self}}" Value="Visible" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="red"></Setter>
</MultiDataTrigger>
</Style.Triggers>
</Style>