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
5124
Setting LabelPresenter Style in code behind - quick snippet
posted

For those looking to set properties on the LabelPresenter (or other classes in the DataPresenter namespace), this code setting the Background on the LabelPresenter can be used as an example:

public MainWindow()
  {
   this.InitializeComponent();
            Style style = new Style();
            style.TargetType = typeof(LabelPresenter);
            Setter s1 = new Setter();
            s1.Property = Infragistics.Windows.DataPresenter.LabelPresenter.BackgroundProperty;
            s1.Value = Brushes.Yellow;
            style.Setters.Add(s1);
            this.Resources.Add(typeof(LabelPresenter), style);
  }

 

  • 430
    posted

    Hi Francis,

    Your post is very useful.I wonder if I get this code in vb.net.

    (though I converted your code to vb.net, it is giving me errors. Converted vb.net code is as below.)

     

           Dim style As Style =  New Style()

                style.TargetType = Type.GetType(LabelPresenter)

                Dim s1 As Setter =  New Setter()

                s1.Property = Infragistics.Windows.DataPresenter.LabelPresenter.BackgroundProperty

                s1.Value = Brushes.Yellow

                style.Setters.Add(s1)

                Me.Resources.Add(Type.GetType(LabelPresenter), style)

     

    Thank you in advance..

     

    Thanks

    Barakath.