Automatically resize window contents in WPF

When debugging my WPF programs, I noticed that when the window size is set, the contra look just fine. But when the window is maximized, the content is placed in the same place as the window did not change. I want the content and window to change proportionally. How can i do this? Sorry if this is a noobish question, but I'm a little new in the WPF era.


XAML code is not yet ready, but here are some of the elements:

<DockPanel>
    <StackPanel DockPanel.Dock="Left">
    ...
    </StackPanel>

    <TabControl DockPanel.Dock="Right">
    ...
    </TabControl>

    <ListView>
    ...
    </ListView>
</DockPanel>
+3
source share
6 answers

This is usually due to the fact that measurement values ​​are set statically, not dynamically. Here's a static approach:

<RowDefinition x:Name="NavigatorRow" Height="120"/>
<RowDefinition x:Name="TaskPanelRow" Height="80"/>

, .

:

<RowDefinition x:Name="NavigatorRow" Height="1*"/> 
<RowDefinition x:Name="TaskPanelRow" Height="80"/>

- 80, , . , . .

, :

<RowDefinition x:Name="NavigatorRow" Height="1*"/>
<RowDefinition x:Name="CalendarRow" Height="2*"/>
<RowDefinition x:Name="TaskPanelRow" Height="80"/>

, Navigator. .

, , , . , , StackPanel, . , .

+5

, , , , Grid.

Xaml, - , !

+3

StackPanels, .

, .

+2

, , . . , HorizontalAlignment = "Stretch" (/ VerticalAlignment), , . , , / .

+1

, - , ? Canvas , ; .

, , . , . , StackPanel DockPanel .

, .

0

Use the WPF grid with the Widht and Height settings configured with the concept of "Number *". For example, Width = "0.6 *" , which is not absolute height, but proportional to the container. General, if you want to resize the content, avoid fixed sizes as much as possible.

  <Grid.RowDefinitions>
       <RowDefinition Height="10*"></RowDefinition>                       
       <RowDefinition Height="*" ></RowDefinition>
  </Grid.RowDefinitions>

Good luck.

0
source

Source: https://habr.com/ru/post/1729162/


All Articles