You must Sign In to post a response.
  • Category: WPF

    Resize WPF window automatically based on screen resolutions

    Hi All,
    I have a MainWindow.xaml with more controls ,so width and height of the
    window is more.
    But I should be able to see the window content in all the resolutions like below
    Please help with the settings or your suggestions.

    1280 x 800
    1024 x 768
    800 x 600

    Thanks in advance....
  • #769781
    Hi Pramod,

    You can use SystemEvents.DisplaySettingsChanged event for this.

    In the Constructor of your window,
    this.Width = System.WIndows.SystemParameters.PrimaryScreenWidth * 0.8;
    this.Height = System.WIndows.SystemParameters.PrimaryScreenHeight * 0.8;
    SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;

    and then,

    private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
    {
    this.Width = System.WIndows.SystemParameters.PrimaryScreenWidth * 0.8;
    this.Height = System.WIndows.SystemParameters.PrimaryScreenHeight * 0.8;
    }

    The above should solve your issue.


  • Sign In to post your comments