locked
Blend - Setting image size in sample data source in a DataGrid RRS feed

  • Question

  • Hello,

    Using a DataGrid I have a sample data source with images in one column.  The images are 16x16 but they are appearing much larger (stretched).  How can I set the images to appear in their correct size?

    Thank you,
    Bob
    Tuesday, September 15, 2009 1:07 PM

Answers

  • Hi Bob,

    check the xaml

    for the image column, it should be:
        <data:DataGridTemplateColumn CellTemplate="{StaticResource Property1Template}" Header="Property1"/>

    For the dataTemplate, it should be:
      <DataTemplate x:Key="Property1Template">
       <StackPanel>
        <Image Source="{Binding Property1}" HorizontalAlignment="Left" Height="16" Width="16"/>
       </StackPanel>
      </DataTemplate>

    notice the height and width is defined in the template

    If you use Blend to drag and drop the image collection to the datagrid, You will find that Blend generated all that xaml for you.
    Thanks, Harry Huang [MSFT]
    • Proposed as answer by Harry.MSFT Tuesday, September 22, 2009 6:08 PM
    • Marked as answer by Bobindy Wednesday, October 7, 2009 2:54 PM
    Tuesday, September 22, 2009 9:50 AM

All replies

  • Hi Bob,

    check the xaml

    for the image column, it should be:
        <data:DataGridTemplateColumn CellTemplate="{StaticResource Property1Template}" Header="Property1"/>

    For the dataTemplate, it should be:
      <DataTemplate x:Key="Property1Template">
       <StackPanel>
        <Image Source="{Binding Property1}" HorizontalAlignment="Left" Height="16" Width="16"/>
       </StackPanel>
      </DataTemplate>

    notice the height and width is defined in the template

    If you use Blend to drag and drop the image collection to the datagrid, You will find that Blend generated all that xaml for you.
    Thanks, Harry Huang [MSFT]
    • Proposed as answer by Harry.MSFT Tuesday, September 22, 2009 6:08 PM
    • Marked as answer by Bobindy Wednesday, October 7, 2009 2:54 PM
    Tuesday, September 22, 2009 9:50 AM
  • Excellent.  Thank you!

    Bob
    Wednesday, October 7, 2009 2:54 PM