我创建了这个数据网格,一切正常,但这有点烦人的问题
这是我的datagrid的截图
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>
任何人都知道我怎么能停止这个?因为它丑陋:))
答案 0 :(得分:2)
WtFudgE,
您好,我想我已经解决了您的问题。您看到的这个“列”实际上不是列,它是行的标题。它允许您一次选择整行,并在运行时调整行高。但是,如果这些不是您需要的功能,您只需设置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>
此外,这是我的网格的屏幕截图(显然没有你的数据 - 我使用了一个带有firstname和lastname的简单Person对象。):
Data Grid http://img34.imageshack.us/img34/5637/demodatagrid.jpg
我希望这有帮助,