WPF: automatic sizing

I would like to know if there was some kind of automatic sizing in WPF.

I mean a way to automatically determine the size related to the resolution of the user's screen, without the need to determine it in the code.

thanks.

+3
source share
2 answers

Firstly, WPF uses device-independent pixels, which means that it will scale accordingly with the DPI selected by the user. However, I do not think that you are asking about DPI here, rather, you are asking about resolution scaling.

, , , ViewBox . , , , Viewbox.

, , , / , . , Grid .

+3

: . , , .

:

HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="..." (set your margin to control the position)

:

<Grid>
ColumnDefinition.Width="*"
RowDefinition.Height="*"

, , /:

<DockPanel>

, - , , :

<ViewBox>

.

, , Windows, DPI, , . , , , .. .

, SystemParameters SystemFonts, :

SystemFonts.CaptionFontSize
SystemFonts.MenuFontSize
SystemFonts.IconFontSize
SystemFonts.StatusFontSize

SystemParameters.IconHeight
SystemParameters.IconVerticalSpacing
SystemParameters.MaximizedPrimaryScreenHeight

75 . , WPF DPI, , .

, , , Windows, , . . , . :

control.Height =
  desiredHeightInActualScreenPixels
    * System.Windows.SystemParameters.MenuHeight
    / System.Windows.Forms.SystemInformation.MenuHeight;
+3

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


All Articles