0
votes

I am using a WindowsFormsHost to display 640x480 images. The WindowsFormsHost works fine using Height="120" Width="160" and Grid.ColumnSpan="3" like this

<Grid Name="MainGrid" Margin="10 10 10 10">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <WindowsFormsHost Name="WindowsFormsHostL" Height="120" Width="160"
        HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0" 
        Grid.ColumnSpan="3"/>

But when I try to double the size of the WindowsFormsHost like this

    <WindowsFormsHost Name="WindowsFormsHostL" Height="240" Width="320"
        HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0" 
        Grid.ColumnSpan="3"/>

the WindowsFormsHost is correct in the .NET xaml viewer but appears to get smaller, do a HorizontalAlignment="Left", and go square. This

Debug.WriteLine(
      "WindowsFormsHostL.ActualHeight " + WindowsFormsHostL.ActualHeight
    + " WindowsFormsHostL.ActualWidth " + WindowsFormsHostL.ActualWidth);

prints this

WindowsFormsHostL.ActualHeight 240 WindowsFormsHostL.ActualWidth 320

at so the runtime seems to think it is correct. I am doing clean builds. What am I miss-understanding? Why can't I simply increase the size of this WindowsFormsHost in the xaml?

1
If you declare a WindowsFormsHost to be a certain size, then it will generally be that size. Are you sure that the images are not being rendered too small in the WinForms control instead? - Sheridan
The images to be rendered are actually larger, 640x480. I have other code that can save the images as .bmps (on a button press) and in both cases (WindowsFormsHost Height/Width 120x160 and 240x320) they are saved as 640x480. - jacknad
Unfortunately, that's not what I asked... your question clearly states the size of the images. I was asking if whatever WinForms image control that you are loading the images into has its size dimension set. - Sheridan
@Sheridan Yes. The imagingControl default size is 150x150. Works perfectly now. If you copy your comment to an answer I'll accept it. Thanks a million. - jacknad

1 Answers

0
votes

Why not set the Row and Column definitions for the Grid to be the size you want to show?

Row Definition:

<RowDefinition Height="240"/> 

Column Definition:

<ColumnDefinition Width="320"/>

Then set your Horizontal and Vertical alignments to 'Stretch' ?