基本上,我在WPF中使用数据网格。如果有一行不包含数据,我希望它是一个空行,我希望它显示如下:
然而,我在尝试实现这一目标时遇到了麻烦。我可以通过创建单独的数据网格并使用转换器将数据分成每个数据库来实现,但它变得非常混乱并且使代码难以维护。
我也可以将行留空,如下所示:
然而,这看起来并不像我想要的那样。任何帮助都表示赞赏,并提前感谢。
datagrid的代码:
<DataGrid Width="265" RowHeight="11.5" CanUserAddRows="False" ItemsSource="{Binding Coupon.SelectionAreas[0].SelectionRows
,Converter={StaticResource DateTimeToSplitDataGridConverter}
,ConverterParameter='Table13Bet'}" AutoGenerateColumns="False" Background="Transparent" RowBackground="Transparent" HeadersVisibility="None" BorderBrush="LightGray" BorderThickness="1,0,1,0" AlternatingRowBackground="{x:Null}" GridLinesVisibility="Horizontal" IsReadOnly="True" SelectionMode="Single" >
<DataGrid.Columns>
<DataGridTemplateColumn Width="27">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate DataType="r:SelectionRow">
<TextBlock Text="{Binding ExpectedOffDate,StringFormat='HH:mm'}" VerticalAlignment="Top" FontFamily="Arial Narrow" FontSize="7.8" HorizontalAlignment="Center" Foreground="{Binding Path=ColourForeground, Converter={StaticResource HexToForegroundColourConverter}}"
Background="{Binding Path=ColourBackground, Converter={StaticResource HexToBackgroundColourConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="27" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="r:SelectionRow">
<TextBlock Text="{Binding SelectionHome.Odd, Converter={StaticResource ChangeZeroToOneOddsToTbcConverter}}" FontFamily="Arial Narrow" VerticalAlignment="Top" FontSize="7.8" HorizontalAlignment="Center" Background="{Binding Path=ColourBackground, Converter={StaticResource HexToBackgroundColourConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="80" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="r:SelectionRow">
<TextBlock Text="{Binding SelectionHome.DisplayName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" FontFamily="Arial Narrow" FontSize="7.8" HorizontalAlignment="Left" Background="{Binding Path=ColourBackground, Converter={StaticResource HexToBackgroundColourConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="24">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="r:SelectionRow">
<TextBlock Text="{Binding SelectionDraw.Odd, Converter={StaticResource ChangeZeroToOneOddsToTbcConverter}}" VerticalAlignment="Top" FontFamily="Arial Narrow" FontSize="7.8" HorizontalAlignment="Center" Background="{Binding Path=ColourBackground, Converter={StaticResource HexToBackgroundColourConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="80" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="r:SelectionRow">
<TextBlock Text="{Binding SelectionAway.DisplayName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" FontFamily="Arial Narrow" FontSize="7.8" HorizontalAlignment="Right" Background="{Binding Path=ColourBackground, Converter={StaticResource HexToBackgroundColourConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="25" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="r:SelectionRow">
<TextBlock Text="{Binding SelectionAway.Odd, Converter={StaticResource ChangeZeroToOneOddsToTbcConverter}}" VerticalAlignment="Top" FontFamily="Arial Narrow" FontSize="7.8" HorizontalAlignment="Center" Background="{Binding Path=ColourBackground, Converter={StaticResource HexToBackgroundColourConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
答案 0 :(得分:0)
可以在某些行
下显示空RowDetails
<DataGrid>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<Grid Height="20"/>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="DetailsVisibility"
Value="{Binding Path=ShowEmptyRow,
Converter={StaticResource BoolToVisible}}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid>
ShowEmptyRow
是一些bool
属性,表示当前DataGridRow下应该有一个空格