The end goal of my application is for a user to compare 2 DataTables. I have 2 DataGrids displayed side-by-side showing the DataTables, with the rows already rearranged so that any matching rows between the 2 tables are aligned.
My desire is that I want any non-matching rows to have a red background, like this:
I have my XAML set up similar to this question:
<DataGrid Name="comparisonGridLeft" ItemsSource="{Binding}" Margin="3" CanUserResizeRows="False">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Match}" Value="true">
<Setter Property="Background" Value="Red"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
With my DependencyProperty "Match" defined similar to this answer:
public class CustomProperties
{
public static DependencyProperty MatchProperty =
DependencyProperty.RegisterAttached("Match",
typeof(bool),
typeof(CustomProperties),
new PropertyMetadata(null));
public static void SetMatch(DependencyObject obj, bool value)
{
obj.SetValue(MatchProperty, value);
}
public static bool GetMatch(DependencyObject obj)
{
return (bool)(obj.GetValue(MatchProperty));
}
}
My final roadblock is that when I iterate through the DataGrids to set the "Match" property to the correct value, I get an error:
error CS1503: Argument 1: cannot convert from 'System.Data.DataRowView' to 'System.Windows.DependencyObject'
foreach (DataRowView leftRow in leftGrid.ItemsSource)
{
foreach (DataRowView rightRow in rightGrid.ItemsSource)
{
bool foundMatch = DetermineIfMatch(leftRow, rightRow);
if (foundMatch)
{
//Throws the compile-time error
CustomProperties.SetMatch(leftRow, true);
foundCloseMatch = true;
break;
}
}
}
Thanks in advance for any help. New to WPF and have been working on this all day to no avail