开发者

Programmatically add style trigger

开发者 https://www.devze.com 2023-01-06 18:27 出处:网络
Can anyone please help how to programatically add the following style: <style> <style.Triggers>开发者_StackOverflow;

Can anyone please help how to programatically add the following style:

<style>
 <style.Triggers>开发者_StackOverflow;
     <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);  
0

精彩评论

暂无评论...
验证码 换一张
取 消