c# - Datagrid奇怪的视觉效果

标签 c# wpf visual-studio datagrid

为什么我的 DataGrid 看起来像这样? enter image description here

我一直在添加一些样式,并且产生了一些“副作用”。有一些线条缺失,各处颜色不一样(中间较浅)。 这是数据网格的 xaml:

<DataGrid x:Name="dataGrid" RowHeaderWidth="0"  CanUserResizeRows="False" HorizontalScrollBarVisibility="Disabled" BorderThickness="0" GridLinesVisibility="None" Height="400" Width="800" HorizontalAlignment="Right" CanUserAddRows="True" Margin="0,210,0,0" Background="Transparent" Foreground="Gray">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Name"  CanUserResize="False" IsReadOnly="True" Binding="{Binding Path=Mp3Title}" Width="300" ></DataGridTextColumn>
                        <DataGridTextColumn Header="Download Info" CanUserResize="False" IsReadOnly="True"  Binding="{Binding Path=DownloadProgress}" Width="250"></DataGridTextColumn>
                        <DataGridTextColumn Header="State" CanUserResize="False" IsReadOnly="True"  Binding="{Binding Path=State}" Width="250"></DataGridTextColumn>
                    </DataGrid.Columns>
                    <DataGrid.Resources>
                        <Style TargetType="{x:Type DataGridColumnHeader}">
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="Margin" Value="80,0" />
                        </Style>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Setter Property="Background" Value="#FF181818"/>
                            <Setter Property="BorderThickness" Value="0"/>
                            <Setter Property="TextBlock.TextAlignment" Value="Left" />
                        </Style>
                    </DataGrid.Resources>
                </DataGrid >

我在文本列中添加项目的 cs 部分

GridInfo data = new GridInfo { Mp3Title = "Some item" ...etc... };
dataGrid.Items.Add(data);

是不是样式搞乱了?

最佳答案

您提供的上述代码看起来不错。也许有一些定义,可能是 Window.Resources

点击时变亮?那么,应用这个可能会有用。

<DataGrid.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFFDFD0A"/>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#FFFDFD0A"/>
</DataGrid.Resources>

您可以根据自己的选择更改颜色。

或者,在没有任何输入(点击)的情况下颜色变浅?你能解释更多吗?

关于c# - Datagrid奇怪的视觉效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37106192/

相关文章:

c++ - 如何摆脱 Visual Studio 中的 "unsafe"警告/错误(strcpy、sprintf、strdup)

c# - 重定向到错误页面并显示用户友好错误

c# - 如何将多行分组为一行?

c# - 在这种情况下有没有比 GOTO 更好的方法?

wpf - 如何在 WPF ListView 中的项目之间添加填充?

wpf - 通过基本的 WPF 指导新手? (我不理解它。)

c# - SplitButton 已锁定 - 无法解锁。为什么?

c# - 进行回滚 - 存储库集成测试

wpf - 简单的 WPF 编程错误会引发蓝屏吗?

c++ - 在 OpenCV 中读取