Prevent resizing of page window in WPF - c#

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...

Related

WPF window with blank space after system scale changed

When I dock simple WPF window to right or left side when the system scaling set to 125% (or higher) and then return the system scale to original value 100% an ugly blank space appear at the bottom of the window as you can see here:
The WPF application is newly created with no change in code (pre-generated).
<Window x:Class="TestScale.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:TestScale"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>
The application is running on 4.7.1 .Net framework
Is this the default behavior? All other applications I've tried seems to behave correctly (they are downsized).
For me it seems that the Window has some problem with Measure/Arrange when the scale is changed and the window is docked to side.
Does anybody faced the same issue?

WPF Colors different from images and web

I've been creating custom color resources in my WPF apps and the colors in the WPF form do not match the original colors from the images.
In the above I have chosen a blue color at random, and made a form with that color as its background. Source code below:
<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="MainWindow" Height="350" Width="525">
<Grid Background="#2E4272">
</Grid>
</Window>
What am I missing?
Edit:
I'm trying to identify the root cause and I'm getting a strange phenomena that I will try to explain. So, first I took an image with a color I liked and used the eye dropper tool in adobe illustrator to determine its color. Then I used that color in my WPF form. They didn't match so I put the two next to each other and did a screen capture.
I then opened that screen capture in illustrator and the part from WPF gave me the right hex value (the same as the original image) and if I put them next to each other they look the same. The part of the screen capture that was the original logo is some other color. So...if I take a screen capture from my computer the WPF color get turned back to the right color and the original color gets changed to something else.

Resize windows size according to title length.

I have a window (WPF) which has a long title. When the size of window is increased dynamically, the title is shown properly. In one case size of window decreased dynamically. In that case full title is not shown. I want to resize the window according to title or textwrap the title, so that full title will be shown. Is there any solution for this?
<Window x:Class="Viewer.View.SelectorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Icon="pack://application:,,,/Images/Viewer.png" WindowStartupLocation="CenterOwner" ResizeMode="CanMinimize"
Title="Registration and visualization from multiple data sets" Height="450" SizeToContent="Width"
>
I don't think that this approach will lead to great success without a lot of effort. Consider the following problems:
Do you really want to fit your window size depending on the title length? If the title is really really long, you are creating a really really big window just because of the title.
It's not that intuitive to put much information into window title
If it's possible to realize at all, you probably have to dig deeper than simply setting some WPF properties.
My solution would be to simply display the title in your view. A simple TextBlock that binds to the window title. So you are much more flexible.

Edit a scroll viewer in the design view of visual studio 2010

I have an input form that I want to edit in visual studios design view. The form is placed within a scroll viewer but since the form is so long I can figure out how to actually scroll the scroll viewer so I can edit further down in the form since the design window is only showing what fits in the window size. Is it possible to edit the entirety of the scroll viewer?
You can either put the form into a UserControl and edit it there without scrollbars or you can increase the size of the Window at design time but leave it at its normal size at run-time. You can achieve the latter effect by adding this to your XAML file:
<Window ...
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
...
d:DesignHeight="1000" d:DesignWidth="1000">

Non-resizable windows with windowStyle=None

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.

Categories