Overriding Columns in XAML

  • Last Post 02 May 2017
DerekMaciak posted this 02 May 2017

You can override the display template and edit template of any WPF column in the datagrid within the content window XAML.

The following list explains the various elements and properties that can be used in the XAML.

  • AB_DataGridColumnOverrideContainer - this notes what column should be overridden and when.
    • Properties:
      • ap_PropertyMetaData: Specifies the property this custom column should be used for.
      • ap_ColumnOverrideUse: When this override should be applied. The values can be Editable, ReadOnly, or Always.
  • AB_DataGridTemplateColumn - The custom column. You can specify anything that inherits from DataGridColumn instead in order to support showing a Hyperlink, image, or something else.
    • Properties/Events:
      • SortMemberPath: Specifies the path of the property that should be used when the user clicks the header of this column. If none is provided, the user will not be able to sort with this column.
      • CopyingCellClipboardContent: Specifies a custom event handler that can be used to provide the content of what should be copied to the clipboard.
      • ae_PastingCellClipboardContent: Specifies a custom event handler that can be used to override the behavior when pasting to a particular cell in the datagrid. There is also a PastingCellClipboardContent event that gets signaled, however, the event args for this do not allow for the canceling of the default paste behavior.
  • AB_DataGridTemplateColumn.CellTemplate - The content of this is a DataTemplate that will be applied when a cell is not currently being edited.
  • AB_DataGridReadOnlyCellContent - This class supports showing errors and error messages that are generated as a result of validating an entity. It also supports binding to a property that determines the background color of a cell.
    • Properties/Events:
      • ap_ContentBinding: The binding which is used to display the content of a cell when it’s not in edit mode.
      • ap_VisualizationType: Specifies how the cell should display data. The values can be Text, Checkbox, Date, or Time. A TextBlock is used to display all visualization types except for Checkbox.
      • ap_BackgroundColorBinding: Used to specify what property to bind to in order to set the background color when not in edit mode.
  • AB_DataGridTemplateColumn.CellEditingTemplate - The content of this property is a DataTemplate that will be applied when a cell enters Edit mode.

Order By: Standard | Newest | Votes
DerekMaciak posted this 02 May 2017

Here is an example of setting an image in a column based on the boolean property IsStatementSent.  If true, I want to set the image to "message-recipient_24_24_32.png".

<base:AB_ContentWindowBase x:Class="WPF.Customers.CustomersExpContent"

                <ResourceDictionary Source="/WPF.DJMWideWorldImporters.Views;component/Customers/CustomersResourceDictionary.xaml"/>
                <!-- Merge the higher level DataPresentationResources in order to extend styles defined in it -->
                <ResourceDictionary Source="/A4DN.Core.WPF.Base;component/DataPresentation/AB_DataPresentationResources.xaml"/>
            <vm:CustomersVM x:Key="CustomersVM"/>
            <local:StatementSentImageConverter x:Key="StatementSentImageConverter" />

        <base:AB_DataGridColumnOverrideContainer ap_PropertyMetaData="{x:Static entity:CustomersEntity.IsStatementSentProperty}" ap_ColumnOverrideUse="AllModes" >
            <base:AB_DataGridTemplateColumn >
                        <Image Source="{Binding Converter={StaticResource StatementSentImageConverter}}" Height="24" ToolTip="{Binding IsStatementSent}"/>

        <base:AB_DataGrid ap_Style="{DynamicResource AB_DataGridDefaultStyle}" base:AB_ContentWindow.ap_IsDefaultContainer="True" base:AB_ContentWindow.ap_IsDefaultSearchAndSelectContainer="True" base:AB_ContentWindow.ap_IsDefaultFilterContainer="True" />
        <base:AB_ListBox ap_Style="{StaticResource DefaultCardStyle}"/>
        <base:AB_ListBox ap_Style="{StaticResource AlbumCardStyle}"/>

Here is what the runtime looks like.

DerekMaciak posted this 02 May 2017

In this case, I created a converter called StatementSendImageConverter that will convert the booleen to an image. Here is the code for the converter.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using BOS.CustomersDataEntity;
using System.Windows.Media.Imaging;

namespace WPF.DJMWideWorldImporters.Views.Customers

        public class StatementSentImageConverter : IValueConverter
            string baseUrl = "/WPF.DJMWideWorldImporters.Shared;component/images/";
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                if (value != null)
                    var customersEntity = value as CustomersEntity;

                    if (customersEntity.IsStatementSent == true)
                       return baseUrl + "message-recipient_24_24_32.png";

                return null;

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                throw new NotImplementedException();