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
Related
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>
I am currently working on a windows form application (C# visual studio).
Is it possible to grey out the entire windows screen when a button is pressed?
How can I work that out?
Is it also possible to grey out the entire screen but leaving an ungreyed space in the middle for a message box for showing some text?
Answers to your question:
Is it possible to grey out the entire windows screen when a button is
pressed?
You can put a control like a panel over the entire window and hide it.
In the button event you then make it visible. Set the background of the panel to gray and vary the transparency to adjust it so until your window visibility beneath it looks right.
This will force the window into a "modal mode" without any way out. So you better have logic for undoing this as well.
How can I work that out?
Make sure you have some event such as completion of an event or query to hide the control or the user will never get back into your application again.
Is it also possible to grey out the entire screen but leaving an
ungreyed space in the middle for a message box for showing some text?
That is more complex and to be honest with you I haven't played with WinForm is some time -- instead doing WPF for desktop. You MAY be able to use clipping but you will have to do quite a bit of research into how to do it. Use Google -- it can be your best friend.
easiest way:use XAML pop-up as described below
<Popup x:Name="pop" IsOpen="False" >
</Popup>
For more details visit below link. http://www.c-sharpcorner.com/UploadFile/mahesh/using-xaml-popup-in-wpf/
After this to blur the main grid on eventhandler for the event which shows the pop-up,set the opacity as shown in below C# code
if (pop.IsOpen == false)
{
pop.IsOpen = true;
grdMain.Opacity = 0.4;
}
else
{
pop.isopen=false;
}
I have a Popup that consists of a grid of labels. The popup sits inside a Canvas like this.
<Canvas x:Name="mainCanvas">
<Popup x:Name="mainPopup"
IsOpen="True"
PlacementTarget="{Binding ElementName=mainCanvas}"
PopupAnimation="Fade"
AllowsTransparency="True"
Placement="Center">
Wrapping inside the canvas (or similar control) is the only way I've found to allow the popup's contents to be transparent.
Anyway, all of this works fine and I see my grid of labels across the center of the screen. What I'd really want though is to display the grid of labels across the bottom of the screen. However when I change Placement="Center" to Placement="Bottom", I don't see the popup at all.
Have you seen this? It is a pretty good explanation about how popup placement works.
I created a test WPF project in Blend and pasted your exact code, then changed Placement to Bottom. I did see the content I added to the popup (a TextBlock with some junk text), but it was hard to see, since it is positioned below mainCanvas (as expected).
So... there must be some other problem aside from the code you showed.
Most recently, while at my mom's house, a phone call came in and the caller ID popped up in a banner on her TV (Comcast). I've seen a similar functionality when the McAfee brings up a virus warning. It was a translucent popup window with the company logo, message and a button or two.
I'd like to mimic this behavior (via C#). This will event driven. My experience in C# is pretty limited, so I'm still feeling out the different libraries. Are there any ideas on where I should start?
I recommended to use WPF. Create new window, that will popup and set next properties:
WindowStyle="None"
AllowsTransparency="True"
Opacity="0.5" //50% transparent
Topmost="True"
Background property will set color of window.
Place on window any controls what you need.
Create this window and show when some event happens:
YourWindow popup = new YourWindow(/*possible args for message on popup, for example*/);
popup.Show();
To place your window in bottom-right corner, as all popups, use next code in windows Loaded event:
this.Left = SystemParameters.WorkArea.Width - this.Width;
this.Top = SystemParameters.WorkArea.Height - this.Height;
How to make animation of window movement you can read in other questions.
If your app is running in the background, you can simply pop up a window and set it to topmost.
Exactly what you do beyond that is going to depend on what type of UI are using (WPF/WinForms.) WPF makes it easier to build a transparent form, as described here:
http://blogs.interknowlogy.com/2007/06/20/transparent-windows-in-wpf-2/
Transparency in WinForms is a little bit harder, but there are some posts about it:
Partial transparency with C# .NET 3.5 WinForms?
A couple of things you will want to do with your pop-up window:
Disable the minimize/maximize/close buttons
Disable the borders
Just put those in your form so it looks better.
-- Dan
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.