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
115
Images in Column Headers
posted

Using only procedual code, how can you place an image in the column header.  Here is some sample code that I am working with and I would like to place the image in the first column header.

XamDataGrid xdgBookTable = new XamDataGrid();WrapPanel myWP = new WrapPanel(); DataSet ds = new DataSet();                                                                     DataTable dt = ds.Tables.Add("Books"); dt.Columns.Add("" , typeof(CheckBox));                                        dt.Columns.Add("Book Name", typeof(string)); CheckBox cb = new CheckBox();String bookName = “Timeline”; dt.Rows.Add(new object[ { cb, bookName}); xdgBookTable.DataSource = ds.Tables[0].DefaultView; 

myWP.Children.Add(xdgBookTable);

 

Thanks for any help. 

 

  • 4850
    Offline posted
    You need to provide a style for the LabelPresenter of the Field in question. The best way to do this in procedural code is to listen to the the FieldLayoutInitialized event. Here is some sample code:
     

    void OnFieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e)

    {

        // Create a style for the label presenter

        Style lbStyle = new Style(typeof(LabelPresenter));

        // Create a factory for an image element

        FrameworkElementFactory fefImage = new FrameworkElementFactory(typeof(Image));

        BitmapImage imageSource = new BitmapImage(new Uri("pack://application:,,,/images/32X32.png"));

        fefImage.SetValue(Image.SourceProperty, imageSource);

        // Set the image as the root element of the visual tree,

        // Note: you may want to add a tree of elements to provide some chrome around the image

        ControlTemplate template = new ControlTemplate(typeof(LabelPresenter));

        template.VisualTree = fefImage;

        lbStyle.Setters.Add(new Setter(Control.TemplateProperty, template));

        // Set the labelprsenter style for the field you are looking for

        e.FieldLayout.Fields["Status"].Settings.LabelPresenterStyle = lbStyle;

    }

    <cingerson> wrote in message news:12374@forums.infragistics.com...

    Using only procedual code, how can you place an image in the column header.  Here is some sample code that I am working with and I would like to place the image in the first column header.

    XamDataGrid xdgBookTable = new XamDataGrid();WrapPanel myWP = new WrapPanel(); DataSet ds = new DataSet();                                                                     DataTable dt = ds.Tables.Add("Books"); dt.Columns.Add("" , typeof(CheckBox));                                        dt.Columns.Add("Book Name", typeof(string)); CheckBox cb = new CheckBox();String bookName = “Timeline”; dt.Rows.Add(new object[ { cb, bookName}); xdgBookTable.DataSource = ds.Tables[0].DefaultView; 

    myWP.Children.Add(xdgBookTable);

     

    Thanks for any help. 

    http://forums.infragistics.com/forums/p/1470/12374.aspx#12374