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!