我试图根据DataGrid列中的值更改边框(我指的是组件)BrushColor(见屏幕)。我想我只是错过了一些愚蠢的事情... How it should see for example when Type of Alarm is High编辑:在App.xaml中标记我想更改的BorderBrush我已经尝试过:
<DataGrid
RowStyle="{DynamicResource DataGridRowStyle2}"
Name="AlertTable"
Grid.Row="5"
BorderBrush="{Binding TypeOfAlert , Converter={StaticResource CellConverter}}" // Got
IsReadOnly="True"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Viditelný"
>
<DataGrid.DataContext>
<local1:CellConverter/>
</DataGrid.DataContext>
<!-- ---- -!>
<DataGrid />
第二次尝试,但它只适用于文本块!:
<DataGridTextColumn
Header="Type of Alert "
Width="*"
Binding="{Binding TypeOfAlert}"
>
<DataGridTextColumn.ElementStyle>
<Style
TargetType="{x:Type TextBlock}"
>
<Setter
Property="Background"
Value="{Binding TypeOfAlert , Converter={StaticResource CellConverter}}"
>
</Setter>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
在应用程序xaml中
<Style x:Key="DataGridRowStyle2" TargetType="{x:Type DataGridRow}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="ValidationErrorTemplate">
<Setter.Value>
<ControlTemplate>
<TextBlock Foreground="Transparent" Margin="2,0,0,0" Text="!" VerticalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border"
CornerRadius="5"
///I want change this BorderBrush
Background="{TemplateBinding Background}" BorderThickness="2" BorderBrush="Red" SnapsToDevicePixels="True">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</SelectiveScrollingGrid.ColumnDefinitions>
<SelectiveScrollingGrid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</SelectiveScrollingGrid.RowDefinitions>
<DataGridCellsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<DataGridDetailsPresenter Visibility="{TemplateBinding DetailsVisibility}"/>
<DataGridRowHeader Visibility="{Binding HeadersVisibility, Converter={x:Static DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
</SelectiveScrollingGrid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
1条答案
按热度按时间lokaqttq1#
DataGridColumn没有BorderBrush(或Border-anything)属性。在第一个代码块中,您为整个DataGrid设置了BorderBrush,这可能根本不是您想要的。据我所知,您想要设置每个DataGridRow的边框,这意味着您需要在RowStyle中设置绑定。