开发者

Wpf Resize object with window

Looked around to find a way to resize bind with the windows resize without explicitly telling my object to grab the windows size.

Here is the code:

    <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <WindowsFormsHost Background="{x:Null}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Name="windowsFormsHos开发者_Go百科t1" VerticalAlignment="Top"  Margin="-1,0,0,0">
        <wf:Panel x:Name="pnlLivePreview" />
    </WindowsFormsHost>
</Grid>

This was followed by the example showed here

Edit: Question: Why doesn't panel resize with the window ?


Simply remove the explicit Width and Height settings, and the HorizontalAlignment and VerticalAlignment settings, thus:

<WindowsFormsHost Background="{x:Null}" 
                  Name="windowsFormsHost1" 
                  Margin="-1,0,0,0">
    <wf:Panel x:Name="pnlLivePreview" />
</WindowsFormsHost>

I'm going to throw a wild guess here, but since this is a WinForms panel, try setting it's Dock property to Fill thus:

    <wf:Panel x:Name="pnlLivePreview" Dock="Fill" />

Really not sure it would work, if it doesn't work in markup, try doing it in code.


Bind your Height/Width to your window's height/width

<Window x:Name="Root_Window">
  <Grid Height="{Binding ElementName=RootWindow, Path=ActualHeight}"
        Width="{Binding ElementName=RootWindow, Path=ActualWidth}">
      <!-- Content Here -->
  </Grid>
</Window>


The answer: Problem is not the panel but the api used to create the content of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜