Home Forums WPF controls Xceed DataGrid for WPF Issues usingValueConverter in a DataTemplate with XCeed DataGridControl

Affichage de 1 message (sur 1 au total)
  • Auteur
  • jxbma
    Post count: 2
    #50404 |

    I have a WPF application with an XCeed DataGridControl.
    I’m trying to use an IValueConverter to convert a data cell (int? value)’s contents as follows.

    If value == null or non-numeric then display ‘N/A’
    If value is numeric then display the value.

    I’m binding the grid to an ObservableCollection of this class:

    public class SampleClass 
    public int? SampleNullableIntValue { get; set; }

    Here is my value converter:

      public class NumericNullConverter : IValueConverter
            private bool IsNumber(object value)
                return value is sbyte
                        || value is byte
                        || value is short
                        || value is ushort
                        || value is int
                        || value is uint
                        || value is long
                        || value is ulong
                        || value is float
                        || value is double
                        || value is decimal;
            public object Convert(object value, Type targetType, 
                                 object parameter, 
                                 System.Globalization.CultureInfo culture)
                if (value == null)
                    return parameter;
                if (IsNumber(value))
                    var num = System.Convert.ToInt64(value);
                    if (num != 0L)
                        return value;
                return parameter;
            public object ConvertBack(
                  object value, Type targetType, object parameter,
                   System.Globalization.CultureInfo culture)
                throw new NotImplementedException();

    Here is my Data Template Definition:

    <DataTemplate x:Key="NumericNullContentTemplate">
        <TextBlock Text="{Binding Converter={StaticResource
                 NumericNullOrZeroConvert}, ConverterParameter='N/A'}" TextAlignment="Center" />

    Here is my XCeed DataGridControl definition, with the DataGridColumn using the above defined template:

         <xcdg:Column SampleNullableIntValue Title="SampleTitle" 
        CellContentTemplate="{StaticResource NumericNullContentTemplate}" 

    I cannot get this to behave correctly.
    Instead of return ‘N/A’ for the case of null values, grid ALWAYS displays a zero (0).
    The Converter returns ‘N/A’ as expected when it encounters NULL.

    I’ve tested the converter independent of the DataGridControl and it works as expected.

    What am I doing wrong here? Is there an issue/bug with XCeed?


Affichage de 1 message (sur 1 au total)
  • Vous devez être connecté pour répondre à ce sujet.