Я не очень похожий на пользовательский интерфейс, но у меня была задача с тем, что казалось простым делом.Изменить цвет фона DataGridCell, если стиль уже установлен?
Мне нужно изменить несколько столбцов фона уже установленного рабочего документа, что, по словам пользователей, будет легче читать. Все, что я читаю, указывает на использование <Style TargetType="DataGridCell">
. Это было бы разумно и легко выполнимо, за исключением того, что есть стили, которые уже применяются к другой цели, и я не могу добавить другую.
Как изменить цвет фона DataGridCell, когда стиль уже установлен?
Это то, что одна из колонн выглядит сейчас
<DataGridTextColumn x:Name="colGoalPercentCases" u:XAMLProperties.GroupName="Cases" Width="*" IsReadOnly="False"
Binding="{Binding Path=GoalPercent_Cases, TargetNullValue='', Mode=TwoWay, StringFormat='{}{0:#,#.00\\%;-#,#.00\\%}',NotifyOnTargetUpdated=True}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="{x:Type TextBox}">
<EventSetter Event="LostFocus" Handler="GoalLostFocus" />
<EventSetter Event="LostKeyboardFocus" Handler="GoalLostKeyboardFocus" />
</Style>
</DataGridTextColumn.EditingElementStyle>
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<Grid MinWidth="{Binding Path=ActualWidth, ElementName=colGoalPercentCases}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Content="CS %" Margin="1,0,10,0" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center"/>
<TextBox x:Name="tbCasePercent" Margin="1,0,10,0" IsReadOnly="True" Grid.Row="1" Grid.Column="0" Width="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right"/>
</Grid>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
EDIT: Добавлен код для сотового Style - Решенный мой вопрос
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="Background" Value="#FFC7D9FF"/>
</Style>
</DataGridTextColumn.CellStyle>
Ах да, является ключевым элементом, который необходимо добавить. Спасибо большое –
Jmyster