I have a requirement where i need to display a line in Datagrid Row Background. So I wrote this code:
<DataGrid.RowBackground>
<LinearGradientBrush EndPoint="0,0" StartPoint="{Binding GradientPoint}" MappingMode="Absolute" SpreadMethod="Repeat">
<GradientStop Color="{Binding LineColor}" Offset="0" />
<GradientStop Color="{Binding LineColor}" Offset="0.1" />
<GradientStop Color="White" Offset="0.1" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</DataGrid.RowBackground>
Now, I can draw a line successfully for the first time. I have some code which does some formatting, and changes the height of Data grid Row. Once it changes the height, I am calling the following code and I assume that the Brush should take the Color, and the Start Point from the binding.And the binding should return the new values to the DataGrid Row Background.
dtMainGrid.Items.Refresh();
dtMainGrid.UpdateLayout();
edit: I also tried to include this, but no help :(
dtMainGrid.InvalidateVisual();
But, the problem is, when I refresh the Items, even the layout, the DataGrid RowBackground brush is not refreshing. It seems it is storing the point and color in the cache and is not refreshing the layout, so my line is not moving because it is not refreshing.
Any help?
Edit: Adding my properties:
private System.Windows.Media.Color lColor;
public System.Windows.Media.Color LineColor
{
get
{
return lColor;
}
set
{
lColor = value;
}
}
public System.Windows.Point GradientPoint { get { return Context.GetContext().GradientPoint; } }
Ok, just in case anyone wonders, the properties are just fine. It is that, it is called for the first time, and for subsequent request, it is not even called. I tested it by putting break point.
Edit 2#: Adding the solution here. Used Data Triggers for the property, as I only could expect four different options in my property Gradient Point, i just had to add 4 Data Triggers like following:
<DataTrigger Binding="{Binding GradientPoint}" Value="1">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,15" MappingMode="Absolute" SpreadMethod="Repeat">
<GradientStop Color="{Binding LineColor}" Offset="0" />
<GradientStop Color="{Binding LineColor}" Offset="0.05" />
<GradientStop Color="White" Offset="0.05" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
Thanks, V