2012-04-27 32 views
8

我有:什麼是簡單的方法來設置CustomGrid的背景單元格顏色?

<CustomControl:GridControl ShowCustomGridLines="True" Grid.Column="2" Grid.Row="0"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition /> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
       <RowDefinition /> 
       <RowDefinition /> 
      </Grid.RowDefinitions> 
     <TextBlock Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Name="txbCaption" Text="{Binding Caption}" /> 
      <CustomControl:GridControl ShowCustomGridLines="True" Grid.Column="2" Grid.Row="1"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition /> 
        <ColumnDefinition /> 
        <ColumnDefinition /> 
       </Grid.ColumnDefinitions> 
       <Grid.RowDefinitions> 
        <RowDefinition /> 
       </Grid.RowDefinitions> 
       <TextBlock Grid.Column="0" Grid.Row="1" Text="П" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
       <TextBlock Grid.Column="1" Grid.Row="1" Text="Ф" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Yellow" /> 
       <TextBlock Grid.Column="2" Grid.Row="1" Text="%" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
      </CustomControl:GridControl> 

我想設置一個文本框的單元格背景(其中背景=「黃」)。爲TextBox設置背景並不能解決問題,因爲我需要爲整個單元設置背景顏色,即使沒有文本。

這怎麼辦?

回答

11

您可以在該區域放置某種類型的面板並設置其背景顏色。例如:

<Rectangle Fill="Black" IsHitTestVisible="False" Grid.Column="1" Grid.Row="1"/> 
2

WPF grid不知道「cell」是什麼。把面板放在那裏,並設置它的顏色。

5

或者在單元格中放置一個邊框,然後在邊框內設置所需的任何控件,以設置邊框的背景顏色屬性。

<Border Grid.Column="0" Grid.Row="0" Background="#FF3C3C3F"> 
    <TextBlock>Some Text</TextBlock> 
</Border> 
3

要設置一整行或列的背景顏色,在該行或列定義補充一點:

<Grid Grid.Row="0" Grid.Column="0" Background="SomeColor"/> 

如果您指定行+列插入你的。 然後你可以插入任何你想要的文本框。

相關問題