I am creating a Notepad like application in WPF. I want to set the window form height and width according to screen size . How can i get Screen height and width ?
Asked
Active
Viewed 2.1k times
5
-
True. Shouldn't assume SO to be an auto-answer-machine that saves on searching the net. – Stephen Chung Mar 13 '11 at 14:28
-
2If you want the window to fit the screen size, why not just maximize it? – Kent Boogaart Mar 13 '11 at 17:34
-
Google redirected me to here as the first choice ;-) – Dabblernl Aug 18 '12 at 09:39
2 Answers
13
Just bind SystemParameters
properties to your window properties.
<Window x:Class="YourWindow"
Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}"
Width="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}">

kyrylomyr
- 12,192
- 8
- 52
- 79
-
2SystemParameters offers resource keys for all its properties. It is better to use DynamicResource instead of bindings. – Marat Khasanov Mar 13 '11 at 20:47
-
This is not working here. "SystemParameters is not supported in a Windows Presentation Foundation (WPF) Project." A shame :| – Malavos Feb 10 '14 at 11:56
8
See System.Windows.SystemParameters
You have properties like
PrimaryScreenWidth
PrimaryScreenHeight
VirtualScreenHeight
VirtualScreenWidth
WorkArea
etc.
This question might help as well: How can I get the active screen dimensions?

Community
- 1
- 1

Fredrik Hedblad
- 83,499
- 23
- 264
- 266