tags:

views:

32

answers:

2

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>
A: 

just refer this link and see

http://www.codeproject.com/KB/WPF/codeVsXAML.aspx

Kishore Kumar
Sorry I need to post the right xaml again on anothyer new thread.. so silly this textbox does not do xml allignment
+2  A: 

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);  
Andrey