0

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="windowsFormsHost1" 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 ?

Community
  • 1
  • 1
Reza M.
  • 1,205
  • 14
  • 33

3 Answers3

2

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.

Aviad P.
  • 32,036
  • 14
  • 103
  • 124
  • You could also remove the `Grid` entirely if there's nothing else going in there. – Dan Puzey Mar 22 '11 at 17:01
  • Yeah, I already tried that, the problem with that is: it just resizes on load, not while the window is resizing. – Reza M. Mar 22 '11 at 17:01
  • My guess is that the `WindowsFormsHost` itself does resize with the window, but the `wf:Panel` inside it does not since it doesn't follow the WPF layout rules. – Aviad P. Mar 22 '11 at 17:05
  • Yeah, I figured as much, looked it up on msdn and it's a window form component. tried adding a autosize=true to it and yet no avail. – Reza M. Mar 22 '11 at 17:08
  • BTW I just tested it without the dock part, and the panel does actually resize with the window, I don't know what the problem is with your markup. – Aviad P. Mar 22 '11 at 17:19
  • I think, I figured it out. The class I send a ref of the panel to, changes the setting for panel... gotta re change afterwards I suppose. – Reza M. Mar 22 '11 at 17:36
  • @Aviad - Yea, it's the api I am working with.... +1 for all the help and new knowledge – Reza M. Mar 22 '11 at 17:58
1

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>
Rachel
  • 130,264
  • 66
  • 304
  • 490
0

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

Reza M.
  • 1,205
  • 14
  • 33