I'm updating a WPF in a project. As I received it, here is how the base window is specified:
<Window x:Class="SomeProject.ButtonForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SomeProject"
Title="ButtonForm" Height="647" Width="379" WindowStyle="None" ResizeMode="CanResizeWithGrip"
SnapsToDevicePixels="True" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
SizeChanged="Resized" Closing="Window_Closing" AllowsTransparency="True" >
Some main things are that WindowStyle is None, ResizeMode is CanResizeWithGrip and AllowsTransparency is True.
What I would like to do is make this window resizable from all four edges without grips. Is there a way to do this directly in the markup? I've seen some projects that implement this, but they involve whole separate files and complicated code-behind. Certainly there is a simpler way.
Check out MahApps.Metro. It may not be exactly what you're looking for, but it'll give your application an updated look with the functionality you're looking for and takes almost no effort.
You may also want to check out this question for some more discussion about custom window chrome.
You have to set ResizeMode to "CanResize" and AllowTransparency to "False" to be able to see the chrome to resize it.
Related
In my WPF application, Need to show a Non-modal window.
I am using MVVM Light framework.
People are suggesting different libraries to do so but is there any suitable control to do that using MVVM Light or using WPF native library?
Need to keep that non-modal window always on top.
Thanks.
To create a non-modal window you won't have to use a framework. The WPF library has enough possibilities to create it.
The quickest solution is to create a new Xaml Window and within the properties of the Xaml Window code, you van specify the TopMost priority, and set it to true.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="NonModalWindow" Height="300" Width="300" TopMost="True">
<Grid>
<!---- Some element defined in your window ---->
</Grid>
</Window>
Once you have created this window it is only a matter of calling it.
new NonModalWindow().Show();
And if you do want to make it into a Modal window you can use to following code.
new NonModalWindow().ShowDialog(); // wooah a contradiction in the code
So I've googled all day trying to find an answer and have come up short. I've found stuff close and maybe even found a solution and just didn't realized it but I cant seem to get the Minimize, Maximize / Restore, and Close buttons to show up (be visible) on my windows 10 machine. No one but myself and another developer who just got new laptops have this issue. I've tried changing my windows theme around and I did get them to show up with I turned some high contrast setting on but no luck otherwise. Despite not being visible they are there and functional because I can click in the area and see the window min, max, restore, close.
We are using .Net 4.0 and a RibbonWindow with a custom theme (BureauBlue.xaml). I'd like to believe it may have something to do with that but I don't know anything about it or where to start unfortunately.
<r:RibbonWindow x:Class="Ztools.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:props="clr-namespace:Ztools.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
IsTabStop="False" Icon="/Ztools;component/ztools32.ico" Height="830" Width="1200" WindowStartupLocation="CenterScreen" WindowState="Normal"
Loaded="RibbonWindow_Loaded" Closing="RibbonWindow_Closing"
xmlns:my="clr-namespace:System;assembly=mscorlib" Title="Ztools 2.0" Name="mainRibbon" FontSize="14" SizeChanged="mainRibbon_SizeChanged" LocationChanged="mainRibbon_LocationChanged"
StateChanged="mainRibbon_StateChanged" Deactivated="mainRibbon_Deactivated" KeyUp="mainRibbon_KeyUp" Background="{x:Null}">
<r:RibbonWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Ztools;component/themes/bureaublue.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</r:RibbonWindow.Resources>
</r:RibbonWindow>
Another thing I noticed but haven't verified by pulling out my old laptop yet is I'm pretty sure the nice looking buttons showed up at design time as well and didn't look like this.
Bonus question/issue is sometimes when our computers go to sleep/hibernate go from docking station to no station (not sure which one or both) the theme bar will also randomly black out like this. If I could look at fixing this at the same time that would be great.
I did change it to a normal Window and was able to see all the buttons correctly but I guess I'd rather not go that route and know what the issue is and solve it.
Any thoughts ideas or suggestions are greatly appreciated.
Edit: So I don't think it has anything to do with the theme? I commented out everything having to do with the theme and they still don't show up... Not sure why I didn't take that simple step a long time ago.
So going to post this again that way anyone with the same or similar issue can at least have an option to fixing their issue... since for some reason it was deleted despite containing valuable information as an alternative solution to the problem.
For now I changed it from a RibbonWindow to a Window an gave my Ribbon a margin of 0,-22,0,0 so things line up and look decent as suggested by a number of other SO posts. The buttons show up now, but aren't the RibbonWindow style so is what it is.
<Window x:Class="Ztools.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:props="clr-namespace:Ztools.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
IsTabStop="False" Icon="/Ztools;component/ztools32.ico" Height="830" Width="1200" WindowStartupLocation="CenterScreen" WindowState="Normal"
Loaded="RibbonWindow_Loaded" Closing="RibbonWindow_Closing"
xmlns:my="clr-namespace:System;assembly=mscorlib" Title="Ztools 2.0" Name="mainRibbon" FontSize="14" SizeChanged="mainRibbon_SizeChanged" LocationChanged="mainRibbon_LocationChanged" StateChanged="mainRibbon_StateChanged" Deactivated="mainRibbon_Deactivated" KeyUp="mainRibbon_KeyUp">
<r:Ribbon Title="Ztools 2.0 (Scale Configuration Editor)" IsTabStop="False" Background="#FFE5E5E5" FontSize="12" FontFamily="Arial" Margin="0,-22,0,0">
</r:Ribbon>
</Window>
The ribbonwindow in version 5 has set WindowStyle="none" by default.
Maybe the WindowStyle is just set to None?
Try set it to "SingleBorderWindow" its original default in the base class.
I not only had the same issue but was able to replicate it in a new project and fix it through this solution although for you it will require moving to a more recent .net version.
The problem seems to stem from using RibbonControlsLibrary. It's is an outdated version of the ribbon controls. As of .net 4.5 Ribbon is native to the framework and by removing the reference you'll be able to use the included RibbonWindow.
Move to a .net version 4.5+ and remove this reference
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
and use
<RibbonWindow>
instead of
<r:RibbonWindow>
I have custom ContentControl
public class MyContentControl: ContentControl
{....}
with Content defined in XAML like this
<controls:MyContentControl x:Name="myContentControl">
<controls:MyContentControl.Content>
<controls:UserControl1 />
</controls:MyContentControl.Content>
</controls:MyContentControl>
Content shows in designer and in the device when I launch my application. But when I try to change Content property programmatically, for example
UserControl2 control2 = new UserControl2();
myContentControl.Content = control2;
MyContentControl shows nothing. Using standard ContentControl give the same result.
Any suggestions are welcome.
I followed your code to make simple code sample to test. There's no problem.
public class CustomContentControl:ContentControl
{//......}
<Grid>
<local:CustomContentControl x:Name="content">
</local:CustomContentControl>
</Grid>
MyUserControl1 myUserControl1 = new MyUserControl1();
content.Content = myUserControl1;
<UserControl
x:Class="AppContent.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppContent"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<TextBox Text="abc"></TextBox>
</Grid>
You might have done some specific settings in your code. #Martin Zikmund's suggestion also was reasonable. You could refer to his suggestion and check your code. After that, if you still could not solve this issue, please provide a Minimal, Complete, and Verifiable example.
This should work. The reason could be that the control does not stretch and is displayed just 0x0 in size. Try to set absolute Width and Height to the control2 and check if it displays. You can also set myContentControl.HorizontalContentStretch and myContentControl.VerticalContentStretch.
You can try running the app in debugger and then use the Live Property Explorer to see what the actual size of the control inside Content is.
Ok, I found out where the things went wrong. I am using different controls for desktop and mobile devices, so I put some of theirs XAML views to the DeviceFamily-Mobile folder. This way they automatically use when needed. I've confused namespaces, because all XAML views in this folder have a root namespace for accessibility reasons. When I was trying to add control to the ContentControl via c#, I didn't resolve namespace where my controls were placed. So I've put XAML view as a childs to the ContentControl, and they staying invisible as none of them has InitializeComponent() method. Adding correct controls with initialization fixed my problem.
I am very grateful for your answers, they pointed me to the right way.
If I create a new WPF application with a simple empty window like the code shown below, I find that all applications which are covered by the WPF app lost touch or stylus reaction. This can only be reproduced when Windows 10 is upgraded to 1803 (10.0.17134.0).
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" Background="Transparent"
Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
I wrote another WPF application to find out what happened. So I add a StylusDown event to the Window like the code shown below:
// This code is in another WPF application.
private void OnStylusDown(object sender, StylusDownEventArgs e)
{
// Set a breakpoint here.
}
But the breakpoint never reached until I closed the transparent WPF window which is on top.
I pushed the very simple code to GitHub: dotnet-campus/TouchIssueOnWindows10.0.17134. Cloning it might help a little.
Why does this happen and how to solve it? Any reply is appreciated.
Updated
Microsoft has fixed this issue in .NET Framework August 2018 Preview of Quality Rollup.
August 30, 2018—KB4346783 (OS Build 17134.254)
Addresses an issue where touch and mouse events were handled differently in Windows Presentation Foundation (WPF) applications that have a transparent overlay window.
Original
After a whole week's debugging, I finally find out the solution.
Just add a ResizeMode="NoResize" property for the Window as the code shown below:
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
#lindexi has posted this issue and this solution into his post. If you want more information about this issue, read win10 17025 touch bug - lindexi for more details. (This post is written in multiple languages, so you'll miss nothing even if you ignore the unknown characters.)
Actually, I still can't figure out why this property helps.
Could anyone explain the reason for this issue?
I am rewriting an old application built in FoxPro and my client doesnt want any change in GUI so I have to make an old DOS style GUI application using wpf, and here is where my problem starts.
The older application was a full screen application so here too I have to make it full screen no task bars..nothing. Now I changed the properties and everything was working very fine in my first window. but as soon as I use window2.showdialog() to invoke my second window, which too should go full screen BOOM...despite of the fact that I am using identical settings second window leaves some space at bottem (though it is border less and all) now I dont know whats going wrong here....
Here is my first window which works perfectly:
<Window x:Class="WpfAppMT.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:mt="clr-namespace:WpfAppMT"
Title="MT" WindowStyle="None" WindowState="Maximized" ResizeMode="CanResize" SizeToContent="WidthAndHeight" Topmost="False" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="640" d:DesignWidth="480">
<Viewbox Stretch="Fill">.....</Viewbox></Window>
here is the screens shot of the first window which is perfectly fine:
and this is the xaml of my second window, which when invoked from the first window's event handler is always cut short at bottom
<Window
x:Class="WpfAppMT.accountheads"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="accountheads" Background="#FF008284" WindowStyle="None" WindowState="Maximized" ResizeMode="CanResize" SizeToContent="WidthAndHeight" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="640" d:DesignWidth="480" KeyDown="Window_KeyDown">
.....</Window>
Here you can see that the second window is not full screen but leaves a lot of space at the bottom I dont understand the reason behind this peculiar behavior...
Apart from that I am facing a peculiar problem the GUI of application looks different on different OS's...I mean I am devolping it on an XP machine where it looks differently(the positions/length/widths), and today when I tested it on windows 7, there is lot of difference in look. You can see that in the second window text box which was supposed to be at the bottom has come up
OK..so after some trial and error I found the solution, In this case problem was with SizeToContent property I have set it to WidthandHeight but it should be set to Manual, so this answers the full screen question but still the prolem with portability persists