I'm trying to disable the maximize capacity (not the maximize button) in a wpf window, but so far nothing has succeded.
I'm using a window with WindowStyle="none", but when I drag the window to the far top of the screen, the OS "maximizes" the window (terribly bad, by the way).
I uploaded 3 pictures to show what is happening exactly.
(however, due to the fact that I don't have 10 reputation, I have to post the links instead. Sorry about that. And I can't put all 3 links, only 2 of them, but the first one is just of the window working normally)
During:
After:
use the window state change event:
private void Window_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == System.Windows.WindowState.Maximized)
{
this.WindowState = System.Windows.WindowState.Normal;
}
}
Set MaxHeight,MinHeight and MaxWidth,MinWidth property for the window.
Example
<Window x:Class="test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" MaxHeight="350" MaxWidth="525" MinHeight="350" MinWidth="525">
</Window>
How do you disable Aero Snap in an application?
Related
How can hide the opened child windows from taskbar when I am showing and hiding the child windows even when I hide the child window the hidden window still appear in the taskbar WPF?
Thanks in advance,
Here is an Example how I show the dialogs:
AlignLocalAxisView alignLocalAxisView = Container.Resolve<AlignLocalAxisView>
(new ParameterOverride("model", AttributesSelectedItems));
OpenedWindowView = alignLocalAxisView;
alignLocalAxisView.Show();
There should be a ShowInTaskbar property for the window.
If your window is defined in XAML, you can set the property deliberately as shown below:
<Window
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"
mc:Ignorable="d"
x:Class="MyApplication.MainWindow"
Title="MainWindow"
Height="350" Width="425"
ShowInTaskbar="False">
You can also set this in your code behind:
this.ShowInTaskbar = false;
This is also applciable to a window created in code behind when called by name.
Window myNewWindow = new Window();
//Set the property to keep the window hidden in the task bar
myNewWindow.ShowInTaskbar = false;
//Then, show the window
myNewWindow.Show();
EDIT: Based on your example code, the following should work
AlignLocalAxisView alignLocalAxisView = Container.Resolve<AlignLocalAxisView>(new ParameterOverride("model", AttributesSelectedItems));
OpenedWindowView = alignLocalAxisView;
//Assuming your view extends the Window class, the following will work
alignLocalAxisView.ShowInTaskbar = false;
alignLocalAxisView.Show();
Hopefully, this will be enough to sort the problem out.
For future reference though, this was a fairly quick solution to look up on google - its generally worth searching for an answer first as it can sometimes be a faster way to solve the problem.
in this case, I reworded your issue to "hide task bar icon for window in wpf". The child window part wasn't really needed in the search, as all windows in WPF are basically the same.
I hope that's of some help.
I am new to WPF and I am trying to understand how to transition between different windows.
I currently have two windows: a LoginWindow and a MainWindow. The LoginWindow opens first and transitions to the MainWindow. However, when this happens and I press close, the debugging in VS17 does not stop. Why is this and how can I make it work properly? I have looked around a bit whereas I found this:
<Application.MainWindow>
<NavigationWindow Source="MainWindow.xaml" Visibility="Visible"/>
</Application.MainWindow>
but it doesn't seem to work. VS simply enteres "break mode"... :(
This is how my App.xaml currently looks like
<Application x:Class="LearningWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LearningWPF"
StartupUri="LoginWindow.xaml">
<Application.MainWindow>
<NavigationWindow Source="MainWindow.xaml" Visibility="Visible"/>
</Application.MainWindow>
<Application.Resources>
</Application.Resources>
Any suggestions as to what I can do or what I am doing wrong?
The problem is because you still have the login window open.
What you can do is override the OnClose event and then forcefully close the application when the main window is closed. Write this in MainWindow.xaml.cs
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Application.Current.Shutdown();
}
Application.Current.Shutdown() will ensure all the windows are closed on close of mainwindow.
I have a 2 monitor system under Windows 7 64 bit .NET 4.5.1
Here are the window and the steps to reproduce a nasty situation that I have:
xaml of the window
<Window x:Class="WindowStyleTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowStyle Test"
WindowStartupLocation="CenterOwner"
WindowStyle="None"
Height="350"
Width="525"
Loaded="MainWindow_OnLoaded">
<Grid>
</Grid>
</Window>
code behind of the window
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
// quick fix to show the taskbar, you can remove this, but it also doesn't work
this.WindowStyle = System.Windows.WindowStyle.ThreeDBorderWindow;
this.WindowState = System.Windows.WindowState.Maximized;
this.WindowStyle = System.Windows.WindowStyle.None;
}
}
Move the maximized window to other monitor with SHIFT+WIN+LEFT or SHIFT+WIN+RIGHT
Now the window should be moved to the other monitor and still maximized
Try to move the window back to the previous/first monitor with SHIFT+WIN+LEFT or SHIFT+WIN+RIGHT
So you wondered why nothing happens? The window doesn't move again!
Me too :-D
Test system: Windows 7 64 bit .NET 4.5.1
test repository
Any ideas to fix this? I think it's a windows issue.
And yes, I need the WindowStyle="None"
I don't see any problems here. The only problem I can see is the short cut key you are using.
You probably want WINDOW + LEFT or WINDOW + RIGHT or WINDOW + UP to move it.
or WINDOW + SHIFT + LEFT/RIGHT to move between monitors.
I work on an application that contains a mixture of Winforms and WPF. The older parts of the app are Winforms (including the "main" application window) with some of the more recent screens being WPF. These WPF windows are typically not launched modally, as the user will often be working simultaneously on different screens.
If the user encounters a warning/error as a result of a particular action on any of the WPF screens, they will usually be notified by a WPF MessageBox (System.Windows.MessageBox). Is there a way to make those message boxes modal at the application level, rather than at the level of the particular screen that launched it? I want to force the user to acknowledge the warning before interacting with the other screens.
Using a System.Windows.Forms.MessageBox seems to work instead seems to work but I would like to stick with the System.Windows.MessageBox. Thanks.
There's no problem with this in WPF. You just should specify Window owner parameter to your MessageBox.Show invokation. Owned message boxes are modal by their nature. For example, use this overloaded version of Show to customize you message box:
public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon);
Here is very simple (although surely working :)) example:
MainWindow.xaml:
<Window x:Class="WpfApplication2_ModalMessageBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button VerticalAlignment="Center" HorizontalAlignment="Center"
Click="Button_Click">Modal</Button>
</Grid>
</Window>
MainWindow.xaml.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(this, "Text", "Caption", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
I have a SWF object embedded in a WindowsFormsHost Control inside a WPF window.
I'd like to add a toolbar over the swf movie.
The problem with the snippet of code I have below, is that when the new child is added to the host control (or the movie is loaded, I haven't figured out which yet), the toolbar is effectively invisible. It seems like the z-index of the swf is for some reason set to the top.
Here is what it looks like:
XAML:
<Grid Name="Player">
<WindowsFormsHost Name="host" Panel.ZIndex="0" />
<Grid Name="toolbar" Panel.ZIndex="1" Height="50"
VerticalAlignment="Bottom">
[play, pause, seek columns go here]
</Grid>
</Grid>
C#:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
flash = new AxShockwaveFlashObjects.AxShockwaveFlash();
host.Child = flash;
flash.LoadMovie(0, [movie]); // Movie plays, but no toolbar :(
}
Any insight on this issue would be much appreciated.
Update: Since no suitable answer was posted, I've placed my own solution below. I realize this is more of a hack than a solution so I'm open to other suggestions.
Here is my hackaround the WindowsFormsHost Z-index issue.
The idea is to place whatever you need to be overlayed nested inside a Popup. Then to update that popup's position as per this answer whenever the window is resized/moved.
Note: You'll probably also want to handle events when the window becomes activated/deactivated, so the pop disappears when the window goes out of focus (or behind another window).
XAML:
<Window [stuff]
LocationChanged="Window_LocationChanged"
SizeChanged="Window_SizeChanged" >
<Grid Name="Player">
[same code as before]
<Popup Name="toolbar_popup" IsOpen="True" PlacementTarget="{Binding ElementName=host}">
[toolbar grid goes here]
</Popup>
</Grid>
</Window>
C#:
private void resetPopup()
{
// Update position
// https://stackoverflow.com/a/2466030/865883
var offset = toolbar_popup.HorizontalOffset;
toolbar_popup.HorizontalOffset = offset + 1;
toolbar_popup.HorizontalOffset = offset;
// Resizing
toolbar_popup.Width = Player.ActualWidth;
toolbar_popup.PlacementRectangle = new Rect(0, host.ActualHeight, 0, 0);
toolbar_popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Top;
}
private void Window_LocationChanged(object sender, EventArgs e)
{ resetPopup(); }
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{ resetPopup(); }
Another solution I've discovered is to use Windows Forms' ElementHost control. Since I'm using a Windows Form inside a WPF window anyway, why not just use an entire Windows Form and save myself Z-Issue headaches.
The ElementHost control is really useful, because I can still use my toolbar UserControl, and embed it inside the Windows Form. I've discovered that adding a child can be finicky with Windows Forms, so here's a snippet describing the solution:
First, toss in the ActiveX object, then an ElementHost Control, using the designer.
Form1.Designer.cs:
private AxShockwaveFlashObjects.AxShockwaveFlash flash;
private System.Windows.Forms.Integration.ElementHost elementHost1;
Form1.cs
public Form1(string source)
{
InitializeComponent();
toolbar = new UserControl1();
this.elementHost1.Child = this.toolbar;
this.flash.LoadMovie(0, source);
}
Note that the child was not set in the designer. I found that for more complex UserControls the designer will complain (though nothing happens at runtime).
This solution is, of course, still not entirely ideal, but it provides the best of both worlds: I can still code my UserControls in XAML, but now I don't have to worry about Z-indexing issues.