Images in Column Headers

This post has 1 Reply | 2 Followers

cingerson
Points 20
Replied On: Tue, Jan 8 2008 3:41 PM

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. 

 

  • Post Points: 20
Replied On: Wed, Jan 9 2008 9:56 AM
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

Joe

  • Post Points: 5
Page 1 of 1 (2 items) | RSS