Reza M.
Reza M.

Reputation: 1223

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

Upvotes: 0

Views: 2300

Answers (3)

Reza M.
Reza M.

Reputation: 1223

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

Upvotes: 0

Aviad P.
Aviad P.

Reputation: 32669

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.

Upvotes: 2

Rachel
Rachel

Reputation: 132618

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>

Upvotes: 1

Related Questions