With xamDataGrid™, xamDataCarousel™, and xamDataPresenter™ you can change the control displayed in a Field. As shown in Specify a ValueEditor for a Field in xamDataGrid, it isn't difficult to switch the editor that a Field is using. What if you don't want an editor in a Field, but perhaps a Button or some other type of content presenter control. With Microsoft® Windows® Presentation Foundation this type of modification isn't complex at all. By making a copy of the CellValuePresenter's Style and changing the ControlTemplate, you can quickly modify what content presenter is used for a Field.
The following procedure assumes you have a data bound xamDataGrid. For more information, see Creating xamDataGrid in XAML. The following steps work for the xamDataCarousel or xamDataPresenter.
Follow these steps to override a Field's CellValuePresenter and use a Button as a content presenter.
- You need to define a custom Style in the Resources section. The following XAML defines a Style for the CellValuePresenter object. The XAML overrides the ControlTemplate and uses a Button as the content presenter. The XAML then binds the Content property of the Button to the data that would be shown in the Cell.
In XAML:
<!-- To customize the contents of a cell, simply create a new Style which targets the CellValuePresenter control. By supplying your own contents for the ControlTemplate for this control, you have complete control over the visual aspect of the cells. --><StyleTargetType="{x:Type igDP:CellValuePresenter}"x:Key="myCustomFieldCell"><SetterProperty="Template"><Setter.Value><ControlTemplateTargetType="{x:Type igDP:CellValuePresenter}"><!-- You can bind the value of the individual cell to properties of the objects in the template by using the Content property --><ButtonContent="{TemplateBinding Content}"/></ControlTemplate></Setter.Value></Setter></Style></Grid.Resources>
- Create an instance of XamDataGrid and name it.
In XAML:
<igDP:XamDataGridx:Name="XamDataGrid1" ...>...</igDP:XamDataGrid>
- Inside xamDataGrid's FieldLayouts object, define the Field you want to use this custom style on, by assigning the Field's CellValuePresenterStyle property off the FieldSettings.
In XAML:
...<igDP:XamDataGrid.FieldLayouts><igDP:FieldLayout><igDP:FieldLayout.Fields><!-- By using the FieldSettings CellValuePresenterStyle property you can target a specific Style to a Field. --><igDP:FieldName="ProductName"><igDP:Field.Settings><igDP:FieldSettingsCellValuePresenterStyle="{StaticResource myCustomFieldCell}"/></igDP:Field.Settings></igDP:Field></igDP:FieldLayout.Fields></igDP:FieldLayout></igDP:XamDataGrid.FieldLayouts>...
- Build and run the project. You should see Buttons in the ProductName Field similar to the image below.

