开发者

WPF crops application window to screen resolution

I have a WP application with a custom window style. The size of the application windows is fixed and is not resizable (client's request).

If the screen resoulution is smaller than the size of application window, the window gets cropped. If I drag the window to get the cropped part into the screen, it stays invisible!

How can I tell WPF to stop cropping the window to the screen resolution so I can still see the entire window if I drag it around?

The code of my window is the following:

  <Window x:Class="AudioApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
   开发者_JS百科     mc:Ignorable="d" 
        d:DesignHeight="540"   d:DesignWidth="1020"
        xmlns:VW="clr-namespace:MyApp.View"
        Title="MyApp" AllowsTransparency="False" 
        WindowStyle="None" Background="#6C6D6C"
        ResizeMode="NoResize" ShowInTaskbar="True"
        WindowStartupLocation="CenterScreen" Width="1005" Height="500"
        Icon="/MyApp;component/MyApp.ico">


Finally I found the solution. I had to set MinWidth and MinHeight properties. I had no idea that those might affect the general cropping of the window.


I don't know whether this trick may fit your (customer) expectations, but I use the following code in several apps.

        //set window size
        this.Width = SystemParameters.MaximizedPrimaryScreenWidth - 6.0 - 2 * SystemParameters.BorderWidth;
        this.Height = SystemParameters.MaximizedPrimaryScreenHeight - 6.0 - 2 * SystemParameters.BorderWidth;
        this.Left = 0.0;
        this.Top = 0.0;

Place it within the Windows.Loaded event handler, and the windows size will fit the whole desktop area. You may check the desktop size, and if it's smaller than the window's original size, you may adjust at best.

That should work even when the window allows no user resizing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜