任何人都可以帮助您以编程方式添加以下样式:
<style>
<style.Triggers>
<Trigger Binding="{Binding CustomerId}" Value ="1"/>
<setter Property="Background" Value="Red"/>
</style.Triggers>
</style>
答案 0 :(得分:13)
你的XAML不正确,但我想你想看到这个:
Style st = new Style();
DataTrigger tg = new DataTrigger()
{
Binding = new Binding("CustomerId"),
Value = 1
};
tg.Setters.Add(new Setter()
{
Property = Control.BackgroundProperty,
Value = ColorConverter.ConvertFromString("Red")
});
st.Triggers.Add(tg);