wpf 中的 Datagrid 在单元格中显示角
Datagrid in wpf showing corner in cell
我有一个 wpf 应用程序,我在其中显示映射到数据网格的日志。我不想要数据网格中的边框和线条。我尝试了一切但无法实现。
我还附加了它在 wpf ui 上的外观。我只想删除边框角。
enter image description here
Xaml代码
<DataGrid
AutoGenerateColumns="False"
EnableRowVirtualization="True"
Height="216"
HorizontalAlignment="Left"
ItemsSource="{Binding FilteredEventLogList}"
Background="{StaticResource PageBackgroundColor}"
RowDetailsVisibilityMode="VisibleWhenSelected"
VerticalAlignment="Top"
Width="614"
RowHeaderWidth="0"
GridLinesVisibility="None"
BorderThickness="1.5,1.5,1.5,1.5"
BorderBrush="Gray"
>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="BorderBrush" Value="{StaticResource PageBackgroundColor}"/>
<Setter Property="BorderThickness" Value="5"/>
<Setter Property="Margin" Value="0,0,0,0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Level}"
Value="Error">
<Setter Property="Foreground" Value="OrangeRed"/>
</DataTrigger>
<DataTrigger Binding="{Binding Level}"
Value="Warning">
<Setter Property="Foreground" Value="Orange"/>
</DataTrigger>
<DataTrigger Binding="{Binding Level}"
Value="Info">
<Setter Property="Foreground" Value="DarkGray"/>
</DataTrigger>
<DataTrigger Binding="{Binding Level}"
Value="Success">
<Setter Property="Foreground" Value="LimeGreen"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding LogTime}"
Header="Time"
Width="Auto"
>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Foreground" Value="white" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
<Setter Property="BorderBrush" Value="{StaticResource PageBackgroundColor}" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding Log}"
Header="Message"
Width="*"
>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="13" />
<Setter Property="Foreground" Value="white" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="BorderBrush" Value="{StaticResource PageBackgroundColor}" />
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<!--<DataGridTextColumn
Binding="{Binding Level}"
Header="Log Type"
Width="100"
>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="15" />
<Setter Property="Foreground" Value="white" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>-->
</DataGrid.Columns>
</DataGrid>
</StackPanel>
您的单元格样式中有一个 BorderThichness 设置为 5。是否必须尝试将其设置为 0?您还可以将 BorderBrush 设置为透明,使其不可见。
我有一个 wpf 应用程序,我在其中显示映射到数据网格的日志。我不想要数据网格中的边框和线条。我尝试了一切但无法实现。 我还附加了它在 wpf ui 上的外观。我只想删除边框角。 enter image description here Xaml代码
<DataGrid
AutoGenerateColumns="False"
EnableRowVirtualization="True"
Height="216"
HorizontalAlignment="Left"
ItemsSource="{Binding FilteredEventLogList}"
Background="{StaticResource PageBackgroundColor}"
RowDetailsVisibilityMode="VisibleWhenSelected"
VerticalAlignment="Top"
Width="614"
RowHeaderWidth="0"
GridLinesVisibility="None"
BorderThickness="1.5,1.5,1.5,1.5"
BorderBrush="Gray"
>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="BorderBrush" Value="{StaticResource PageBackgroundColor}"/>
<Setter Property="BorderThickness" Value="5"/>
<Setter Property="Margin" Value="0,0,0,0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Level}"
Value="Error">
<Setter Property="Foreground" Value="OrangeRed"/>
</DataTrigger>
<DataTrigger Binding="{Binding Level}"
Value="Warning">
<Setter Property="Foreground" Value="Orange"/>
</DataTrigger>
<DataTrigger Binding="{Binding Level}"
Value="Info">
<Setter Property="Foreground" Value="DarkGray"/>
</DataTrigger>
<DataTrigger Binding="{Binding Level}"
Value="Success">
<Setter Property="Foreground" Value="LimeGreen"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding LogTime}"
Header="Time"
Width="Auto"
>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Foreground" Value="white" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
<Setter Property="BorderBrush" Value="{StaticResource PageBackgroundColor}" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding Log}"
Header="Message"
Width="*"
>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="13" />
<Setter Property="Foreground" Value="white" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="BorderBrush" Value="{StaticResource PageBackgroundColor}" />
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<!--<DataGridTextColumn
Binding="{Binding Level}"
Header="Log Type"
Width="100"
>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="15" />
<Setter Property="Foreground" Value="white" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="{StaticResource PageBackgroundColor}"/>
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>-->
</DataGrid.Columns>
</DataGrid>
</StackPanel>
您的单元格样式中有一个 BorderThichness 设置为 5。是否必须尝试将其设置为 0?您还可以将 BorderBrush 设置为透明,使其不可见。