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

Viewing 1 post (of 1 total)
  • Author
    Posts
  • jxbma
    Participant
    Post count: 2
    #50404 |

    Hi:
    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" />
    </DataTemplate>

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

     <xcdg:DataGridControl> 
      <xcdg:DataGridControl.Columns>
         <xcdg:Column SampleNullableIntValue Title="SampleTitle" 
        CellContentTemplate="{StaticResource NumericNullContentTemplate}" 
        Width="100"/>
       </xcdg:DataGridControl.Columns>
     </xcdg:DataGridControl> 

    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?

    Thanks,
    JohnB

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.