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
125
XAMDataGrid ComboBoxField Converter Binding
posted

Hello - We are evaluating your product and have a question regarding binding converters.

We have a ComboBox in our XamDataGrid.  It's ItemSource is an observable collection of id/value pairs.  The selected value of the ComboBox is bound to a property in our view model.  Everything works fine if the bound property is a native string.  However, if we attempt to bind to a property of a complex type using a converter, the value coming into the converter is always null.

Here is the XAML (ItemsSource is bound in code behind):

<igDP:ComboBoxField Name="CustomerId" Converter="{StaticResource idToStringConverter}" 
                      IsEditable="True" IsEnabled="True">
  
<igDP:ComboBoxField.EditorStyle>
      
<Style TargetType="igEditors:XamComboEditor">
         
<Setter Property="ValuePath" Value="Id" />
         
<Setter Property="DisplayMemberPath" Value="DisplayName" />
      
</Style>
  
</igDP:ComboBoxField.EditorStyle>
</igDP:ComboBoxField>

Here is our Converter:

 public class IdToStringConverter : IValueConverter 
  {
      public object Convert ( object value, Type targetType, object parameter,
                                System.Globalization.
CultureInfo culture )
  
{
           return ( value is Id) ? ( ( Id ) value ).Value: null;
  
}

       public object ConvertBack ( object value, Type targetType, object parameter, 
                                 System.Globalization.
CultureInfo culture )
  
{
           return ( value is string ) ? new Id( value as string ): null;
   
}
  }

Here is the property we are trying to bind to in our ViewModel:
public Id CustomerId { set; get; }

When we bind to a native WPF DataGrid ComboboxColumn, it is simply this:

<DataGridComboBoxColumn
          SelectedValueBinding
="{Binding Path=CustomerId, 
                                
Converter={StaticResource idToStringConverter}}"
         
SelectedValuePath="Id"
         
DisplayMemberPath="DisplayName"/>

We have searched your forums and samples but have not found a straightforward answer.

Thank you