Keep window maximized wpf - wpf

I need a window to stay maximized, so I use WindowState="Maximized" and ResizeMode="NoResize"> but the user can minimize it by trying to drag the window. Is there any way to disable it?

Try by setting WindowStyle="None".

Related

WindowStyle None and touch input

In Windows 10, when using touch device like Surface, touching an input control like a TextBox in a not maximized window, causes moving the whole window up, so that the user can see what he is typing (if keyboard is docked). But it does not happen when WindowStyle is set to none. Why it does not happen? We need this behavior in our app. Can it be fixed on WindowStyle=None? I found it's not connected with it's style - there are no build in triggers or something. We need WindowsStyle=None for custom close button bar (we want the bar to be transparent, only the button is visible).
I faced a similar issue trying to get my application to react to the presence of the Windows 10 touch keyboard properly, but it wouldn't do so unless WindowStyle was set to something other than None.
Struggled with it for a while, until I decided to just try and style the Window myself and removing the borders manually, which led me to discover the WindowChrome class.
The WindowChrome documentation mentions this about WindowStyle="None":
One way to customize the appearance of a WPF application window is to set the Window.WindowStyle property to None. This removes the non-client frame from the window and leaves only the client area, to which you can apply a custom style. However, when the non-client frame is removed, you also lose the system features and behaviors that it provides, such as caption buttons and window resizing. Another side effect is that the window will cover the Windows taskbar when it is maximized. Setting WindowStyle.None enables you to create a completely custom application, but also requires that you implement custom logic in your application to emulate standard window behavior.
So it seems that because this non-client (or OS) frame is missing, it causes the application to not be able to react to the keyboards presence.
The solution is to implement a custom WindowChrome. This can be done like this:
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
Title="MainWindow" Height="350" Width="525" WindowState="Maximized">
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome NonClientFrameEdges="None"
UseAeroCaptionButtons="False"
CornerRadius="0"
GlassFrameThickness="0"
ResizeBorderThickness="0"
CaptionHeight="0" />
</shell:WindowChrome.WindowChrome>
<Grid Background="DarkOrange">
<TextBlock Text="TEST" VerticalAlignment="Center"
HorizontalAlignment="Center" FontSize="32" />
</Grid>
</Window>
If you absolutely must use WindowStyle="None", then according to the documentation above, the Window logic must be custom. Fortunately there's a nice example from Microsoft on how to write custom logic to react to the presence of a touch keyboard: See this link.
If you would like to add your own custom buttons to the title bar, check out this excellent post about styling your Window.
Hope this helps!
UPDATE:
After further investigation, it turned out that this solution only worked on Windows 10 version 1903. When tried on 1809 which we use in production, it didn't work. The reason is that apparently Microsoft have changed the way applications react to the touch keyboard when in full-screen mode.
This can be easily tested by maximizing Explorer in both versions of Windows, and to see how in 1809 nothing happens, but in 1903 the Window is resized to fit the remaining space on the screen.
Another important thing I noticed is that when I start the application from Visual Studio (whether debugger is attached or not), when the touch screen shows up, the UI doesn't react to it, but when I run the executable from explorer, then it does work. So in my testing I would always build, then go to bin\Debug, and start the exe from there.
Take the Grid Layout divide it into 3 rows and add the one custom button to the top right corner of row and on that button event handler do the Window closing code and same for minimizing
and Set the WindowStyle=none

Click through semit transparent WPF application

I created a WPF application that has an overlay mode. In this mode, the whole application gets semi transparent. I'd now like to be able to click through this window to operate with elements behind it [other program UI's, desktop icons etc.]
I wonder if there is the possibility to configure the window right away to represent this behaviour. I set up my application window like this:
WindowStyle="None" AllowsTransparency="True" Opacity="0.5" Background="Black" IsHitTestVisible="True" Focusable="True" IsTabStop="False"
If I set the Background to x:Null or Transparent, I can click through the application. However, the application is not visible at all any more then.
If this is not possible directly, I thought about another solution:
When clicking on the Application, minimize it, execute another mouse click, and then maximize the application. I found some example code for a global mouse click which looks like this:
MouseEventArgs e = new MouseEventArgs(Mouse.PrimaryDevice, 0);
e.RoutedEvent = Mouse.MouseEnterEvent;
youUIElement.RaiseEvent(e);
// Or
InputManager.Current.ProcessInput(e);
However, I think this will not work when trying to do double-clicks.
So, general desire in a few words:
Semi-transparent WPF application, always on top, click-through. Also Keyboard input should pass through.
I set up a special hotkey that brings the application back.
Any helps / ideas?

WPF Window ornament nomenclature

Winforms can switch the ControlBox, Maximize and Minimize buttons on and off. I can't seem to find the equivalent properties to control the window ornaments in WPF. What's the correct nomenclature so I can look up this stuff in msdn?
You can change this by setting the ResizeMode of the window
EG:
ResizeMode="NoResize"
or
WindowStyle="ToolWindow"
will show no minimize/maximize buttons

Can't see WPF control on top Winform Control

I want to show WPF control on top Winform Control.
I want that the WPF Button will appear on top on the Winform TextBox.
The result is that the WPF control is hidden in the back of the winform TextBox and I can't see it.
Why is that?
This is my code:
<UserControl x:Class="Philips.PmsCT.Host.Applications.ExamApplication.ScanRulerComponent.WPFHostWF"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Width="800" Height="120">
<Grid>
<WindowsFormsHost >
<wf:TextBox BackColor="LightBlue" />
</WindowsFormsHost>
<Button Width="100" Height="25" Background="Red"/>
</Grid>
You seem to have the Airspace problem.
So you can rearrange the two controls, that they are layouted next to each other, not on top of each other or use the Wpf TextBox or you have to really bend over backwards to mitigate the airspace problem all together.
All WPF controls render in one native window. You can check it via SPY++ for example.
Almost each WindowsForm Control renders in it own window. Again, you can check it via SPY++.
You want to produce behavior when one window A(WPF) is covered by another window B(Winform control). At the same time you want window B is covered by A(wpf button). I don't know if it can be possible without any hook.
Possible solutions is:
1. Host WPF inside WinForm Panel, where TextBox is.
2. Create WPF form with only required button and show it over first form.
In according to the Microsoft docs: "Visible WindowsFormsHost elements are always drawn on top of other WPF elements, and they are unaffected by z-order."

WPF - Hide minimize button of a window

In WPF, how can I hide the minimize button (only the minimize, not also the maximize...) of a window.
The code in this forum almost work for me. The behavior of that code is that it's disabled the minimize button. But, how hide it?
http://forums.silverlight.net/forums/p/222067/532926.aspx
How about disabling the resize attribute?
ResizeMode="NoResize"
I think you would have to hide the default window title and draw your own titlebar.
e.g.: C# WPF Custom Title Bar Tutorial
and Moving a WPF Window with Custom Chrome

Resources