Shivendra
Shivendra

Reputation: 53

how can i make resize to controls(Panel ,Grid) itself when window is maximize in .net

I create a small application in which, i want when my window(WPF) is maximized it's controls are also resized according to window size.I tried this code-

 If Me.WindowState = Windows.WindowState.Maximized Then
        Me.WindowState = Windows.WindowState.Normal
        Me.Width = 820
        Me.Height = 440
        Me.Grid1.Width = 780
        Me.Grid1.Height = 400
        Me.StackPanel1.Height = 360
        Me.StackPanel1.Width = 140
        Me.StackPanel2.Height = 360
        Me.StackPanel2.Width = 600
 Else If Me.WindowState = Windows.WindowState.Normal Then
        Me.WindowState = Windows.WindowState.Maximized
        'Me.Width = 1350
        'Me.Height = 600
        Me.Grid1.Width = 1300
        Me.Grid1.Height = 600
        Me.StackPanel1.Height = 460
        Me.StackPanel1.Width = 200
        Me.StackPanel2.Height = 460
        Me.StackPanel2.Width = 800

Upvotes: 1

Views: 773

Answers (3)

Dennis
Dennis

Reputation: 1547

You should use a table-layout panel, and doc your controls inside!

Upvotes: 0

HuRN
HuRN

Reputation: 71

You can do it directly from XAML: using HorizontalAlignment/VerticalAlignment properies or with Binding to element's Width/Height in complex cases. Here is example from my project:

<GroupBox .... Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TreeView, AncestorLevel=1}, Path=ActualWidth}">

Upvotes: 0

tray2002
tray2002

Reputation: 188

Why you can't wrap your controls inside Grid? When you set columns width and rows height using *, it will change columns and rows size whenever window be resized. Also controls should have HorizontalAlignment and VerticalAlignment set to Stretch.

Upvotes: 1

Related Questions