Can anyone please help how to programatically add the following style:
<style>
<style.Triggers>
<Trigger Binding="{Binding CustomerId}" Value ="1"/>
<setter Property="Background" Value="Red"/>
</style.Triggers>
</style>
Your XAML is incorrect, but I guess you want to see this:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With