2010-05-17 102 views
0

這是我的xaml代碼,其中我有2個字段放置在一個模板列下。如何格式化數據網格中的DataGridTemplateColumn中的數據

現在我得到的格式是這樣的輸出,這樣我可以betweeen這2列

Color 

red  image1 

green  image2 

green  image2 

white  image6 

使輸出看起來不錯指定的空間。

我如何定義它們之間的空間,使得它看起來像上面的一個

現在THW輸出是這

 
    color 

    Redimage1 

    greenimage2 

    greenimage2 

    whiteimage6 
<sdk:DataGridTemplateColumn Header="Color" Width="80"> 
    <sdk:DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <StackPanel Loaded ="StackPanel_Loaded" Orientation="Horizontal" Background="Transparent"> 
       <TextBlock Text="{Binding Color}" TextWrapping="NoWrap" HorizontalAlignment="Center" Foreground="Blue"></TextBlock> 
       <Image x:Name="imgTargetScore" Source ="{Binding ColorImage}" Width="20" Height="20" Stretch ="Fill"/> 
      </StackPanel> 
     </DataTemplate> 
    </sdk:DataGridTemplateColumn.CellTemplate> 
</sdk:DataGridTemplateColumn> 

尋找熱塑成型前一個解決方案

感謝狀提前

王子

回答

0

你需要把一點Margin在你的TextBlock和/或圖像控制:

<TextBlock Text="{Binding Color}" Margin="0,0,5,0" TextWrapping="NoWrap" HorizontalAlignment="Center" Foreground="Blue" /> 

這個例子把一個爲5px保證金的TextBlock的右邊緣。如果您希望圖像垂直排列,那麼您可能也希望將TextBlock設置爲一個設置寬度,默認情況下它只與文本中的文本一樣長。