Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
815
Creating a style from codebehind
posted

Ok, so I am starting to get a hang of WPF by now. 

What I can't figure out yet is how to create a style dynamically from my .cs file. I can create the style, I can create the setters, but I can't attach the setters to the style. 

Can someone please provide some working code for that?

 

Thank you.

Parents
  • 69686
    Verified Answer
    posted

    Hello,

    You have to add the setters in the Setters collection of the style:

    Style myStyle = new Style(typeof(CellValuePresenter));

    myStyle.Setters.Add(new Setter(CellValuePresenter.BackgroundProperty, Brushes.AliceBlue));

    myStyle.Setters.Add(new Setter(CellValuePresenter.FontSizeProperty, 16.0));

    xamDataGrid1.FieldSettings.CellValuePresenterStyle = myStyle;

    Hope this helps.

Reply Children
No Data