1

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" 
        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">
JustAMartin
  • 13,165
  • 18
  • 99
  • 183

2 Answers2

2

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.

JustAMartin
  • 13,165
  • 18
  • 99
  • 183
1

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.

Mario Vernari
  • 6,649
  • 1
  • 32
  • 44
  • The application contains some graphical elements with fixed size. That means - window should never be resized or else its appearance will be messed up. – JustAMartin Aug 06 '11 at 12:06
  • Sorry, but at this point I am not sure to understand. If the window must keep its size, and the screen could be set to a lower resoultion, how could you fit the UI area? – Mario Vernari Aug 06 '11 at 12:34
  • I do not want to fit it, I want the previously hidden part of the window to become visible if I drag the window. But now if I drag the window, I see that WPF still cuts away the part which was offscreen and does not redraw it any more, even if it is now back on the screen and should be visible. – JustAMartin Aug 06 '11 at 13:07
  • Hmmm...I see. Boh, it seems an issue of the graphics driver, or something like that. I would try to implement a mechanism to detect any screen resolution change, and reposition the window accordingly. Take a look here: http://stackoverflow.com/questions/442337/detect-change-of-resolution-c-winforms – Mario Vernari Aug 06 '11 at 13:46
  • 1
    Yes, I too think that it has to do something with drivers or DirectX. But it happens even if I launch my app after I change the resolution, so there is no use for resolution change detection. WPF just is not drawing the offscreen part even after it gets on screen. – JustAMartin Aug 06 '11 at 15:54
  • Are you sure it is not any issue on *that* machine? Could you try on another PC, maybe with a different OS? – Mario Vernari Aug 06 '11 at 16:02