我创建了以下DataGrid设计:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:leartWPF" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="leartWPF.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<local:GroupDataSource x:Key="GroupDataSourceDataSource" d:IsDataSource="True"/>
<DataTemplate x:Key="GroupCellTemplete" >
<Grid>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding }" />
</Grid>
</DataTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot" Margin="0" DataContext="{Binding Source={StaticResource GroupDataSourceDataSource}}">
<DataGrid Margin="0" HeadersVisibility="None" ItemsSource="{Binding Groups, Mode=OneWay}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Groups" IsReadOnly="True" CellTemplate="{DynamicResource GroupCellTemplete}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
ExpressionBlend中的如下所示:
然而,当我运行应用程序时,它看起来像这样:
我做错了什么?
答案 0 :(得分:1)
试试这个:
dataGrid.RowHeight = double.NaN;