2013-07-22 39 views
0

我正在使用WindowsFormsHost來顯示640x480圖像。 的WindowsFormsHost工作正常使用HEIGHT = 「120」 WIDTH = 「160」 和Grid.ColumnSpan = 「3」 這樣的如何確定WindowsFormsHost的大小?

<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"/> 

但是當我嘗試這樣

<WindowsFormsHost Name="WindowsFormsHostL" Height="240" Width="320" 
     HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0" 
     Grid.ColumnSpan="3"/> 
的WindowsFormsHost的規模擴大一倍

WindowsFormsHost在.NET xaml查看器中是正確的,但似乎變小了,請執行Horizo​​ntalAlignment =「Left」,然後轉爲正方形。這

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

打印此

WindowsFormsHostL.ActualHeight 240 WindowsFormsHostL.ActualWidth 320 

在這樣的運行似乎認爲它是正確的。我正在做乾淨的構建。我在想什麼 - 理解?爲什麼我不能簡單地增加xaml中這個WindowsFormsHost的大小?

+1

如果你聲明一個'WindowsFormsHost'是一個特定的大小,那麼它通常就是這個大小。您確定圖像在「WinForms」控件中的顯示效果不是很小嗎? – Sheridan

+0

要渲染的圖像實際上更大,640x480。我有其他代碼可以將圖像保存爲.bmps(在按下按鈕時),並且在這兩種情況下(WindowsFormsHost高度/寬度120x160和240x320),它們都保存爲640x480。 – jacknad

+0

不幸的是,這不是我問的問題......你的問題清楚地說明了圖像的大小。我在問,是否將任何'WinForms'圖像控件加載到其*尺寸設置中。 – Sheridan

回答

0

爲什麼不將網格的行和列定義設置爲要顯示的大小?

行定義:

<RowDefinition Height="240"/> 

列定義:

<ColumnDefinition Width="320"/> 

然後設置你的水平和垂直對齊到 '全屏'?

+0

這可能會起作用,但我在所有6列中的後續行上都有其他控件。 – jacknad