Creating a Style in code behind

前端 未结 2 954
遇见更好的自我
遇见更好的自我 2020-12-02 20:25

Does anyone know how to create a wpf Style in code behind, I can\'t find anything on the web or MSDN docs. I have tried this but it is not working:

Style s =         


        
2条回答
  •  日久生厌
    2020-12-02 21:05

    This should get you what you need:

    Style style = new Style
    {
        TargetType = typeof(Control)
    };
    style.Setters.Add(new Setter(Control.ForegroundProperty, Brushes.Green));
    myControl.Style = style;
    

提交回复
热议问题