0

I am trying to use an IValueConverter for a specific field in a DataGrid in my WPF project. What I find is that the converter is never called, even though the DataGrid is populated as data arrives.

I have the following code:

<UserControl.Resources>
    <sol:RfidConverter x:Key="rfidConverter" />
</UserControl.Resources>
...
<DataGrid AutoGenerateColumns="False" Name="TagGrid" VerticalAlignment="Stretch" ItemsSource="{Binding}">
    <DataGrid.Columns>
        <DataGridTextColumn IsReadOnly="True" Header="Tag ID" Width="200" Binding="{Binding Rfid, Converter={StaticResource rfidConverter}}"></DataGridTextColumn>
        <DataGridCheckBoxColumn Header="Delete" Width="Auto" Binding="{Binding ToDelete}"></DataGridCheckBoxColumn>
    </DataGrid.Columns>
</DataGrid>

And in C#:

// Tags is an ObservableCollection<Tag>
TagGrid.DataContext = a.GetActiveItem<Project>().Tags;

And my Converter's code:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    string val = ((Int64)value).ToString("x").PadLeft(8, '0');
    return val;
}

I think there is an easy answer to why my converter is not getting called. I set a breakpoint on the line that begins "string val = ..." and the breakpoint is never hit, even though blank entries are added to my DataGrid. This is my first WPF project. Help is much appreciated. Thanks!

Sheridan
  • 68,826
  • 24
  • 143
  • 183
user2434237
  • 21
  • 1
  • 5
  • Well, that was it. Thanks a million. – user2434237 Jan 30 '14 at 04:22
  • @bogza.anton, please add your comment into an answer, so that this question can be set as answered. If you could add a bit more explanation to help future users, it would be appreciated. Many thanks. – Sheridan Jan 30 '14 at 09:26

1 Answers1

0

I have reproduced your example. Binding and conversion work is performed. Recheck the field name bindings (Rfid).

bogza.anton
  • 606
  • 11
  • 21