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
105
Setting style elements in code
posted

Hi,

 There are plenty of examples and documentation on how to set style elements from XAML, but is there any documentation for setting these elements in code?  I can set basics like foreground, background, etc., but I am looking to build multiple grids on the fly and perhaps with different styling elements. For example, in code i'd like to set header elements but have been unsuccessful in doing so.  I've tried several things like:

xdg.FieldLayoutSettings.HeaderPresenterStyle = hp.Style;

where hp is a HeaderPresenter object, but I've had no luck.  I also find it odd that FieldLayouts has a DataPresenter reference, but not a HeaderPresenter reference. I guess I'm primilarily looking to set header styling in code.  Any examples or documentation on this?

Thanks,

Matt

Parents
No Data
Reply
  • 4850
    Offline posted

    Hi Matt,

    Creating styles in procedural code with visual trees is much more verbose. It is much easier and clearer to write them in xaml. If that is not possible for your scenario this post contains a little sample of how to do it in code http://forums.infragistics.com/forums/p/1470/12501.aspx#12501. Notice that in this example the ControlTemplate's VisualTree property is set to an instance of a FrameworkElementFactory. In this simple case the visual tree consists of a single Image element.

    To build up more elaborate trees you would set the root element's FrameworkElementFactory (e.g. representing a StackPanel or Grid)  to the VisualTree property of the ControlTemplate and then call its AppendChild method one ore more times with other FrameworkElementFactorys representing its child elements and so on.

    The DataPresenter reference returns the associated DataPresenterBase derived object, XamDataPresenter, XamDataGrid or XamDataCarousel. The HeaderPresenter is just an element that represents the Field labels in a XamDataGrid. There can be more than one of these.

    I hope this helps,

    Joe 

Children
No Data