gpt4 book ai didi

WPF数据网格问题

转载 作者:行者123 更新时间:2023-12-02 07:09:17 25 4
gpt4 key购买 nike

我创建了这个数据网格,一切正常,但有一个恼人的小问题

这是我的数据网格的屏幕截图

http://users.telenet.be/i_dislike_mushrooms/datagridproblem.JPG

但是左边有一个小“柱子”,这让我非常恼火。这是我的代码:

<Window x:Class="IMDB.ML.Window1"
Name="This"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="IMDB.ML" Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}"
Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"
WindowStartupLocation="CenterScreen" WindowStyle="None">
<Window.Resources>
<Style x:Key="HeaderTextStyle" TargetType="{x:Type dg:DataGridColumnHeader}">
<Setter Property="Background" Value="DarkSlateGray" />
<Setter Property="Foreground" Value="White" />
</Style>
</Window.Resources>
<Grid>
<Menu Height="22" Name="TopMenu" FontFamily="Verdana" FontSize="12" VerticalAlignment="Top" Background="DarkSlateGray">
<Menu.BitmapEffect>
<DropShadowBitmapEffect />
</Menu.BitmapEffect>
<MenuItem Header="_File" Background="Transparent" Foreground="White">
<MenuItem Header="_Close" Background="DarkSlateGray" Foreground="White" Click="close_Click" />
</MenuItem>
<MenuItem Header="_Edit" Background="Transparent" Foreground="White">
</MenuItem>
</Menu>
<dg:DataGrid Background="DarkSlateGray" ItemsSource="{Binding ElementName=This, Path=GameData}" ColumnWidth="*"
Margin="5,35,5,5" AutoGenerateColumns="False" ColumnHeaderStyle="{StaticResource HeaderTextStyle}">
<dg:DataGrid.Columns>
<dg:DataGridTextColumn IsReadOnly="True" Binding="{Binding Title}" Header="Title" />
<dg:DataGridTextColumn IsReadOnly="True" Width="60" Binding="{Binding Score}" Header="Score" />
<dg:DataGridTextColumn IsReadOnly="True" Width="60" Binding="{Binding Year}" Header="Year" />
<dg:DataGridTextColumn IsReadOnly="True" Binding="{Binding Genre}" Header="Genre" />
<dg:DataGridHyperlinkColumn IsReadOnly="True" Width="200" Binding="{Binding Link}" Header="Link" />
<dg:DataGridCheckBoxColumn Width="50" Binding="{Binding Seen}" Header="Seen" />
</dg:DataGrid.Columns>
</dg:DataGrid>
</Grid>

有人知道我该如何停止吗?因为它很丑:)

最佳答案

WtFudgeE,

您好,我想我已经找到了解决您问题的方法。您看到的这个“列”实际上并不是一列,它是行的标题。它允许您一次选择整行,并在运行时调整行高。但是,如果这些不是您需要的功能,您只需设置 RowHeaderWidth="0" 即可解决此问题。这是您的更新代码:

<Window x:Class="IMDB.ML.Window1"
Name="This"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="IMDB.ML" Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}"
Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"
WindowStartupLocation="CenterScreen" WindowStyle="None">
<Window.Resources>
<Style x:Key="HeaderTextStyle" TargetType="{x:Type dg:DataGridColumnHeader}">
<Setter Property="Background" Value="DarkSlateGray" />
<Setter Property="Foreground" Value="White" />
</Style>
</Window.Resources>
<Grid>
<Menu Height="22" Name="TopMenu" FontFamily="Verdana" FontSize="12" VerticalAlignment="Top" Background="DarkSlateGray">
<Menu.BitmapEffect>
<DropShadowBitmapEffect />
</Menu.BitmapEffect>
<MenuItem Header="_File" Background="Transparent" Foreground="White">
<MenuItem Header="_Close" Background="DarkSlateGray" Foreground="White" Click="close_Click" />
</MenuItem>
<MenuItem Header="_Edit" Background="Transparent" Foreground="White">
</MenuItem>
</Menu>
<dg:DataGrid Background="DarkSlateGray" ItemsSource="{Binding ElementName=This, Path=GameData}" ColumnWidth="*"
Margin="5,35,5,5" AutoGenerateColumns="False" RowHeaderWidth="0" ColumnHeaderStyle="{StaticResource HeaderTextStyle}">
<dg:DataGrid.Columns>
<dg:DataGridTextColumn IsReadOnly="True" Binding="{Binding Title}" Header="Title" />
<dg:DataGridTextColumn IsReadOnly="True" Width="60" Binding="{Binding Score}" Header="Score" />
<dg:DataGridTextColumn IsReadOnly="True" Width="60" Binding="{Binding Year}" Header="Year" />
<dg:DataGridTextColumn IsReadOnly="True" Binding="{Binding Genre}" Header="Genre" />
<dg:DataGridHyperlinkColumn IsReadOnly="True" Width="200" Binding="{Binding Link}" Header="Link" />
<dg:DataGridCheckBoxColumn Width="50" Binding="{Binding Seen}" Header="Seen" />
</dg:DataGrid.Columns>
</dg:DataGrid>
</Grid>

此外,这是我的网格的屏幕截图(显然没有您的网格的数据 - 我使用了一个带有名字和姓氏的简单 Person 对象。):

Data Grid http://img34.imageshack.us/img34/5637/demodatagrid.jpg

希望这对您有所帮助,

谢谢!

关于WPF数据网格问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1770562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com