2016-05-24 63 views
1

本質上,我在WPF中使用一個數據網格。如果不包含任何數據行,我希望它是一個空行,我希望它下面顯示:格式化數據網格中的行看起來空白

enter image description here

但是我有真正的麻煩努力實現這一目標。我可以通過創建單獨的數據網格並使用轉換器將數據拆分爲每個數據網格來實現,但它變得非常混亂,並且使代碼難以維護。

我也可以留下空白行看起來如下做到這一點:

enter image description here

但是這並不太我想怎麼看。任何幫助表示感謝,並提前感謝。

代碼數據網格:

<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

已添加代碼 – Spitfire5793

回答

0

所以能夠在一定行

<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顯示空RowDetails是一些bool屬性,其指示應該有電流DataGridRow下的空的空間

+0

我已經與你的建議一起去了,但我碰到的問題是我無法設置showEmptyRow綁定來獲取每個單獨的行,它的要求類似於我的ItemSource。我無法看到設置dataType的方式,正如我在Cell模板中所做的一樣。有沒有解決的辦法? – Spitfire5793

+0

我得到它的工作,似乎它在運行時工作正常,只是在設計時間它是有趣的。謝謝 – Spitfire5793