mahapps metrowindow resize issue - c#

I have created MahApps MetroWindow with such parameters
<controls:MetroWindow x:Class="....MainWindow2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:viewModels="clr-namespace:...ViewModels"
xmlns:views="clr-namespace:...Views"
xmlns:enums="clr-namespace:...Enums"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:command="http://www.galasoft.ch/mvvmlight"
xmlns:commands="clr-namespace:...Commands"
xmlns:common="clr-namespace:...Common"
Title="MainWindow"
Height="1080"
Width="1920"
ShowTitleBar="False"
ShowCloseButton="False"
ShowMinButton="False"
ShowMaxRestoreButton="False"
ShowSystemMenuOnRightClick="False"
ShowIconOnTitleBar="False"
WindowState="Maximized"
WindowStyle="None"
ResizeMode="NoResize"
IgnoreTaskbarOnMaximize="True"
ShowInTaskbar="False"
UseNoneWindowStyle="True"
IsWindowDraggable="False"
Background="{StaticResource BackgroundBrush}"
DataContext="{Binding MainPageVM, Source={StaticResource ViewModelLocator}}">
It's a fullscreen window and always on top. When i turn off my display and then turn it on, this window shrinks and never return to the previous size, until reboot. What is the source of this issue? And what are possible solutions?

I can't reproduce the issue, but I'd suggest to try without
Height="1080"
Width="1920"
or replacing them with
Height="{Binding SystemParameters.PrimaryScreenHeight}"
Width="{Binding SystemParameters.PrimaryScreenWidth}"

Related

Custom Window with all sides Grip

Recently I want to make a custom window with WPF for my program.
Here is the code of the Window:
<Window x:Class="Test.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:Test"
mc:Ignorable="d"
Title="Test" Height="450" Width="850" Background="Transparent" AllowsTransparency="True" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" WindowStyle="None">
</Window>
I want to recreate a titlebar that I set the WindowStyle to None.
Now I need to resize the window with the grip. However, the Grip will not work anymore if I set the WindowStyle to None.
In spite I can set the ResizeMode to CanResizeWithGrip. Whereas, it only works on the bottom right side of the Window.
I want to make the Grip work all sides of the window. How can I achieve it?
You can set the ResizeBorderThickness property of a WindowChrome to make a custom window resizable:
<Window x:Class="WpfApp1.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"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" WindowStyle="None">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>
<Grid Background="Yellow">
<TextBlock>Resizable window...</TextBlock>
</Grid>
</Window>

Set Dockpanel width and height as same as Window width and height in wpf

I have created main window in this window created dockpanel for binding user control value in main window like as below,
<Window x:Class="WpfApplication2.DMMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Height="{Binding SystemParameters.PrimaryScreenHeight}"
Width="{Binding SystemParameters.PrimaryScreenWidth}">
<DockPanel Width="1254" Height="1200" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="mainPanel" VerticalAlignment="Top" />
</Window>
In this code you can see given width and height for dockpanel. I need this height and width need to bind as same as window width. I have used actual width and height and also sizetocontent but nothing happened as expected. Please give your suggestion.
As you are using dock panel you do not need to set it explicitly. Incase you want , you can restrict further by using minimum height and width, but no mandatory.
<Window x:Class="WpfApplication2.DMMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Height="{Binding SystemParameters.PrimaryScreenHeight}"
Width="{Binding SystemParameters.PrimaryScreenWidth}">
<DockPanel x:Name="mainPanel"
MinHeight ="{Binding SystemParameters.PrimaryScreenHeight}"
MinWidth ="{Binding SystemParameters.PrimaryScreenWidth}" />
</Window>
You can add Stretch property as below,
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0" x:Name="mainPanel" />
Hope it will work
<Window x:Class="WpfApplication2.DMMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="NoResize"
WindowState="Maximized"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Height="{Binding SystemParameters.PrimaryScreenHeight}"
Width="{Binding SystemParameters.PrimaryScreenWidth}">
<DockPanel x:Name="mainPanel" />
</Window>

Display wpf window on top of the screen

I am developing a WPF application. I need to to display a window on top of the screen like a window taskbar.
This is my xaml code:
<Window x:Class="testProject.Notification.TestWindow"
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:testProject.Notification"
mc:Ignorable="d"
Title="TestWindow" Height="80" Topmost="True" ResizeMode="NoResize" WindowStyle="None">
<Grid Background="Blue"/>
</Window>
I need a bluewindow like below(screen shot from mac osx application):
This will do the trick for you
<Window x:Class="AtDTopCorner.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="35"
WindowStyle="None"
WindowStartupLocation="Manual"
Top="5"
Left="0"
AllowsTransparency="True"
Background="Blue"
Width="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth}}">
</Window>

UI Elements placed in the wrong place while running in full screen

I am having a C# WPF application that runs in full screen. When I place a button in the top right of the canvas and run the application the button doesn't appear. What i figured it out is that the canvas is larger than the screen although I made it the same width and height as the screen resolutions.
PS: The application is working fine on another computer and the canvas size is correct but when I run it on my laptop or PC the same problem appears.
<Window x:Name="Mywindow" x:Class="Graduation_Project.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="WidthAndHeight" Height="768" Width="1366" WindowStyle="None"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
WindowState="Maximized" Topmost="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Canvas Name="workspace">
<Label x:Name="Print" Content="Label" Canvas.Left="57" Canvas.Top="719" Width="74"/>
</Canvas>
</Window>
Remove the Height="768" and Width="1366" properties from the Window.

WPF change screen resolution in C#

I have a WPF Application and when I change my screen resolution to 800 X 600 or other smaller resolutions then, I can not see all my form. I see just up side of my form. How may I overcome this?
<local:WorkControl x:Class="Mzaddress.AddressControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Mzaddress"
Title="Adresse" mc:Ignorable="d" d:DesignWidth="840"
xmlns:r="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
Loaded="WorkControl_Loaded" x:Name="myCntl"
FontFamily="Arial" FontSize="12" xmlns:my="clr-namespace:Mzaddress.UserControls"
VerticalAlignment="Top" VerticalContentAlignment="Stretch"
local:HelpProvider.HelpParameter="AddressControl">
<local:WorkControl.Resources>
Try this little sample und put your form into such simple ScrollViewer.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Grid Height="600" Width="800" Background="Green"/>
</ScrollViewer>

Categories