Basically, I want to create a window that looks like the following:
alt text http://www.thex9.net/screenshots/2009-10-15_1347.png
However, the window shouldn't be resizable (the one in the screenshot is) but must retain the glass border. The XAML for the window in the screenshot is as follows:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window" Title="MainWindow" WindowStyle="None">
<Grid x:Name="LayoutRoot"/>
</Window>
Is it possible to create a window which looks similar to the one in my screenshot but is not resizable? Any help would be very much appreciated.
Probably you can get desired result by:
ResizeMode=
XAML object property which can take have following states:
NoResize - A window cannot be resized. The Minimize and Maximize buttons are not displayed in the title bar.
CanMinimize - A window can only be minimized and restored. The Minimize and Maximize buttons are both shown, but only the Minimize button is enabled.
CanResize - A window can be resized. The Minimize and Maximize buttons are both shown and enabled.
CanResizeWithGrip - A window can be resized. The Minimize and Maximize buttons are both shown and enabled. A resize grip appears in the bottom-right corner of the window.
One way to accomplish a fixed size Window while retaining the border is to set the Min[Width|Height] and Max[Width|Height] properties to be the same value. The border will still show the resize cursor, but the user will not be able to change the size of the Window.
If the fact that the border still indicates that it's resizable bothers you, the next step is to set the ResizeMode="NoResize", but then you have to start drawing your own Aero glass if you want to retain the glass edges.
Related
I have a WPF window that should display as a dialog over my main app window. The dialog should have no title bar and not be resizable. I removed the title bar by setting the WindowStyle and ResizeMode in the xaml:
<Window
...
WindowStyle="None"
ResizeMode="NoResize">
The problem is that this also seems to remove the window border and drop-shadow effect.
I found this suggestion to use WindowChrome, but it doesn't seem to work for me, when I try it I get a thick black solid shadow that doesn't look right.
This question How to remove the title bar from a window but keep the border explains that to keep the border the window needs to be made resizable, but the window needs to be NOT be resizable. The MinHeight/MaxHeight/MinWidth/MaxWidth can be set equal to prevent the window from being resized, but the user still sees the mouse cursor change to the resize cursor when they move it to the window border which is not good.
How can I remove the title bar, keep the standard border and drop-shadow effect, and have the window not resizable?
I have a WPF app that is set to a specific size for a reason. However the user still has the ability to resize the page. I have set all the maximum page sizes and have achieved three different results, none of which suit my need.
1) The window goes full screen with my app in the top left corner. The rest of the screen is filled with the page background colour.
2) The window goes full screen, page stays central and the rest of the screen is filled with white space.
3) This is the worst solution... The window resizes and shows all the junk i have lying around outside of the page!
All i want to do is prevent someone from changing the window size at all! I am new to wpf and especially new to xaml so want time to learn how to set up auto resizing properly. unfortunately now is not that time (deadlines!).
Thanks
All i want to do is prevent someone from changing the window size at all!
Set the ResizeMode property of the Window to NoResize then:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="Window13" Height="300" Width="300" ResizeMode="NoResize">
...
If you do want the user to be able to resize the window it can never have a fixed size...
I have a WPF window with WindowStyle="None" and ResizeMode="CanResizeWithGrip" and when I rightclick somewhere on the form, I get this showing up (I forgot what the control itself is called..)
The control which asks me if I want to Move, Size, Minimize, Maximize or close the window.. I'm wondering how I can get rid of this.
Any ideas?
When creating a WPF window with AllowsTransparency="True" WindowStyle="None" and maximizing it via this.WindowState = WindowState.Maximized; the Window gets bigger than my screen.
When setting AllowTransparency="False" i have a border around my Window, but the window won't get bigger than my screen.
In my Case I have a 1920x1080 screen and the window becomes 1934x1094.
On my 1280x1024 screen the window will become 1294x1038.
The Window will become still as big as this, whether or not AllowTransparency is enabled or not, yet with it disabled it works properly.
Setting AllowTransparency before maximizing doesen't work and throws an InvalidOperationException.
How to get a WPF window without a Windows-style border, but yet to maximize properly?
A couple year late to the party but just increase your this.borderthickness for the SizeChanged event like so:
<Window x:Class="MyApp.MainWindow"
ResizeMode="CanResize"
WindowStyle="SingleBorderWindow"
SizeChanged="Window_SizeChanged">
....
Code
....
</Window>
public void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.BorderThickness = new System.Windows.Thickness(8);
}
else
{
this.BorderThickness = new System.Windows.Thickness(0);
}
}
It seems a pretty common issue. It appears you'll have to bind your height and width to the actual height/width of the screen as stated in this StackOverflow post:
Borderless window application takes up more space than my screen resolution.
I hope that solves the issue you're facing.
If you only care about the correct dimensions of your window and have no trouble with the appearance, you can wrap the contents of the window in System.Windows.Controls.Canvas like this:
<Canvas Name="MyCanvas" Width="auto" Height="auto">
...
</Canvas>
Then you can use MyCanvas.ActualWidth and MyCanvas.ActualHeight to get the resolution of the current screen, with DPI settings taken into account and in device independent units.
It doesn't add any margins like the maximized window itself does.
It should work with multiple monitors too.
(Canvas accepts UIElements as children, so you should be able to use it with any content.)
Unfortunately there is no good solution to this other than to make a WindowStyle="None" window without resizing, and handle everything yourself. This means your own maximize/minimize/restore buttons that set the window dimensions to fit the screen. Your own live caption area for dragging. Your own borders with the appropriate cursors. Your own double-click handler to maximize/restore. Your own routine for checking the mouse position against the height of the screen for drag-to-dock. Etc. You get the idea. It's a pain in the neck, but if you do it once at least you'll have it for all future projects. Unfortunately you will lose the "Aero" animations, but alas.
I also want to point out one reason why this issue is very important. In at least some cases, WPF can't make full use of accelerated graphics when windows span two monitors (as they normally do any time a window is maximized). That means performance of D3DImage, as well as any Effect, suffers when the window is maximized. It was happening for me, and many of my users, which is what drew my attention to this issue.
set this property of you window.
MinHeight="100"
MinWidth="100"
Height="auto"
Width="auto"
Hope this will work
I'm creating simple presentation app. It have to be fullscreen and UI have to be responsive eg. it have to scale depending on resolution. Is there a way to strech WPF window to over whole screen?
You should only need to do a couple things:
On your Window, set WindowState="Maximized", ResizeMode="NoResize", and WindowStyle="None".
Wrap your "slide" presenter in a Viewbox with Stretch="Uniform". That will cause the slides to scale uniformly to fill the window, while maintaining their original aspect ratio.
Set the window's background to whichever matte color you want. If the slide aspect ratio does not match the display aspect ratio, there will be empty regions to the left/right or top/bottom of the slides, and you may want to control the color of those regions. I recommend Black.
Setting the WindowState to Maximized should do the trick.
Something like this:
<Window WindowState="Maximized" WindowStyle="None">
...
</Window>