I have a WPF application containing a datagrid. Datagrid is attached to my OrderBlock object, which contains a list of order types.
<DataGrid DataContext="{Binding OrderBlock}" Name="dataGridOrdersGood" ItemsSource="{Binding Orders}"
This works great and displays well in my datagrid. There is one property in my list (StatusGood), although I would like to display it as a drop-down field where there can be only two values: โSendโ or โHoldโ.
If the value in the combo box is โHoldโ, I would like the string to change to another. It is ideal to use a linear gradient from silver to yellow. I tried the code below - literally just trying to rotate the red line at the moment, but nothing happens. I do not see what is wrong with my code below. The trigger part is very close to the bottom of the code below. I am new to WPF and struggling with this at the moment. The code below is mainly derived from a very good entry, which can be found here, http://www.codeproject.com/Articles/586132/WPF-DataGrid-Custommization-using-Style-and-Templa
<Style x:Key="DG_Row" TargetType="{x:Type DataGridRow}"> <Setter Property="Background" Value="LightGreen"/> <Setter Property="Opacity" Value="1"/> <Setter Property="Padding" Value="3,2,2,3"/> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridRow}"> <Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <Border.Background> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop Offset="0" Color="Transparent"/> <GradientStop Offset="1" Color="Silver"/> </LinearGradientBrush> </Border.Background> <SelectiveScrollingGrid> <SelectiveScrollingGrid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </SelectiveScrollingGrid.ColumnDefinitions> <SelectiveScrollingGrid.RowDefinitions> <RowDefinition Height="20" /> <RowDefinition Height="Auto" /> </SelectiveScrollingGrid.RowDefinitions> <DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> <DataGridDetailsPresenter Grid.Row="1" Grid.Column="1" SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Visibility="{TemplateBinding DetailsVisibility}" /> <DataGridRowHeader Grid.RowSpan="2" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/> </SelectiveScrollingGrid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="Normal_AlternatingRow"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="DGR_Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#AAF0C570" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="DGR_Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#AAFF7F00" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Normal_Selected"> <Storyboard> </Storyboard> </VisualState> <VisualState x:Name="MouseOver"> <Storyboard> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Border> </ControlTemplate> </Setter.Value> <Style.Triggers> <DataTrigger Binding="{Binding Active}" Value="Hold"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers> </Setter> </Style>
As always, any help would be great. thanks M
source share