2010-05-17 104 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设置为一个设置宽度,默认情况下它只与文本中的文本一样长。