We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding base class property against multiple columns to use ValueConverter to change results

Thread ID:





112365 Sep 18,2013 09:13 PM UTC Nov 22,2013 08:51 AM UTC WPF 1
Tags: GridControl
Chris Flippo
Asked On September 18, 2013 09:13 PM UTC

I have a base class called Security with multiple subclasses (Stock,  Future, etc)
public class Security
    public string Symbol {get;set;}
public class Stock:Security
    public string RIC {get;set;}
    public string Sector {get;set;}
public class Future:Security
     public string RIC{get;set;}
     public DateTime Expiration {get;set;}
These securities are used as properties in an Order class
public class Order
    public string OrderID {get;set;}
    public Security Security{get;set;}
My viewmodel exposes a ObservableCollection<Order> where the Order's Security could be Future or Stock. I am adding columns to a GridDataControl which is bound to the collection of orders. I then use a ValueConverter in the binding to determine which subclass type each Security is so that I can pull the property that should be exposed for that type. In the case of the Expiration column that I added below, I return null for any Stock securities since they don't have that property, but return the proper value for the Futures.
public class SecurityToExpiryConverter:IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    Security sec = value as Security;
    if (sec == null) throw new ArgumentException("value", "Must be of type Security");
    Future f = sec as Future;
    if (f !=null) return f.Expiration.ToString("mm/DD/yyyy");
    return null;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    throw new NotImplementedException();
XAML below
        <c:SecurityToExpiryConverter x:Key="ExpiryConverter" />
        <c:SecurityToUnderlierConverter x:Key="UnderConverter" />
Binding="{Binding Path=Security, Converter={StaticResource UnderConverter}}"
AutoFit="True" IsReadOnly="True" AllowFilter="True"
Binding="{Binding Path=Security,Converter={StaticResource ExpiryConverter}}"
AutoFit="True" IsReadOnly="True" AllowFilter="True"
My problem is that even though I am specifying a specific binding for each of these VisibleColumns with their own ValueConverter, the only value converter that gets used is the one used in the first column for given MappingName. This makes the values displayed in these two columns the same, and in this case they will equal the Ticker column's ValueConverter output. If you switch the order of the columns in the XAML, they will both use the ExpiryConverter.
These columns both have the same MappingName="Security" right now, which I know is not right, but I am not sure what I should switch it to. This mapping name needs to be pointed to a property on the Order object, and it looks like if I point it at any property that is not bound yet (such as OrderID), it will work, even if that property is unrelated to the Path used in the actual Binding. That is a nasty hack, and not easily supported beyond this simple example.
I guess GridDataControl uses some internal Dictionary keyed off the MappingName's to the binding's, even if you specify your own Binding, and that is making the grid use the same ValueConverter.
Any suggestions on a way around this?

Shakul Hameed M [Syncfusion]
Replied On November 22, 2013 08:51 AM UTC

Hi Chris,

Thanks for contacting Syncfusion support.

We have analyzed your query. Our GridDataControl displays the value based on reflection. Hence you can’t achieve this requirement by using GridDataControl. However you can achieve this requirement by using our SfDataGrid. We have created the sample based on your requirement and please check the sample under following location,

Sample: SfGridWithValueConverter.zip

Please let us know if you need further assistance.


Shakul Hameed


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon