2011-03-26 121 views
0

我需要使我的DataGrid中的所有圖像具有相同的大小。圖像在很多地方都是單元格模板內部的項目。如何將大小樣式應用於所有人?如何設置DataGrid單元格模板中的圖像大小?

UPD代碼示例:

    <DataGrid.Columns> 
         <DataGridTemplateColumn> 
          <DataGridTemplateColumn.CellTemplate> 
           <DataTemplate> 
            <Image Source="Resources/Image1.png"/> 
           </DataTemplate> 
          </DataGridTemplateColumn.CellTemplate> 
         </DataGridTemplateColumn> 
         // some other columns with text or images 
        </DataGrid.Columns> 
+0

如果您可以提供您正在使用的模板或綁定信息,那麼每個人都會更容易理解您的意思。 **我的意思是發佈一些代碼**。 – 2011-03-26 08:53:40

回答

1

您可以創建一個風格,形象的TargetType的控制你的尺寸,然後應用到所有的圖像。在你的資源字典

下面去

<Style x:Key="smallImageStyleKey" TargetType="Image"> 
     <Setter Property="Width" Value="32" /> 
     <Setter Property="Height" Value="32" /> 
    </Style> 

然後修改XAML爲您的圖片看起來像

<Image Source="Resources/Image1.png" Style="{StaticResource smallImageStyleKey}"/> 

個人而言,我會把每個圖像的ViewBox,並應用該樣式儘管如此。

理想情況下,您應該首先調整所有圖像的大小,然後再調整大小,而不是在WPF中調整大小。

+0

爲什麼當我爲沒有鍵的圖像目標類型指定樣式時不起作用? – user626528 2011-03-26 10:23:10

相關問題