resizable Custom Window in WPF - c#

I am needing to make a custom window with WindowStyle.None, AllowsTransparency = true, etc.
and "resizeable"
how con help me to create resizeable this?
tanx...

The most simple solution is to implement the ResizeMode property, setting it to "CanResizeWithGrip".
<Window x:Class="TestProject.ScratchWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Opacity="1.0"
ResizeMode="CanResizeWithGrip"
WindowStyle="None"
AllowsTransparency="True"
Title="Test Window">
<!-- Window Contents Here -->
</Window>

Related

how to stop right click on TtitleBar in a WPF application

Writing a program using WPF (with MahApps) In C# and wondering how can I disable a user being able to right click the TitleBar and brining up the window options menu?
Edit1: to confirm I would like to keep the min/max/close button on the bar, just remove the right click event
There is a new property in MahApps v2.x called ShowSystemMenuOnRightClick.
<mah:MetroWindow x:Class="MetroDemo.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:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MahApps.Metro - Demo Application"
Width="900"
Height="600"
mah:DialogParticipation.Register="{Binding}"
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
ShowIconOnTitleBar="True"
ShowSystemMenuOnRightClick="False"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
</mah:MetroWindow>

WPF: How do I bind a window's ShowInTaskbar property to code-behind value?

I am attempting to bind my window's "ShowInTaskbar" property to a definition in the code-behind, but it is not recognized. I also cannot programmatically assign the value in code-behind. I can only manipulate it by directly editing the xaml, which is not ideal in my situation.
<Window x:Class="WPFTest.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:WPFTest"
mc:Ignorable="d"
FontFamily="Segoe UI Light"
FontSize="14"
Title="WPF Test"
Name="Window"
Icon="/Resources/icon.ico"
Height="500"
Width="600"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
Loaded="Window_Loaded"
StateChanged="Window_StateChanged"
Closing="Window_Closing"
ShowInTaskbar="{Binding ShowInTaskbar}"
>
<Grid></Grid>
</Window>
The property I have in the code-behind:
private bool _showInTaskbar
public bool ShowInTaskbar
{
get
{
return _showInTaskbar;
}
set
{
_showInTaskbar = value;
OnPropertyChanged("ShowInTaskbar");
}
}
I have also tried:
Window.ShowInTaskbar = false;
Why is my binding not being recognized? Or, how can I simply define it in code-behind?
Ugh. It was because I was using the same name as the window naturally inherits. Once I changed my property to "ShowIconInTaskbar" I bound it and it functions properly.

Grid control can't cover the whole page and leaves a space at the top

I have a default grid control defined in xaml:
<Page
x:Class="App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
</Grid>
</Page>
And this grid does not start from the top of the page as you can see from the picture below:
One way to achieve this is to set a negative margin like this:
<Page
x:Class="App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Margin="0,-26.667,0,0">
</Grid>
</Page>
So it will look like in this picture:
However, I've watched some of Bob Tabor's videos like this one and all of his default controls starts right from the top of the page.
What is the problem here and how can I solve it without setting a negative margin?
Well status bar is there by default.
You have 2 options:
Hide it -> Hide Status bar in Windows Phone 8.1 Universal Apps
put your content under it:
var applicationView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
applicationView.SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);
You may wish to read this for additional info:
http://blogs.msdn.com/b/amar/archive/2014/05/12/status-bar-in-windows-phone-8-1.aspx

Make WPF MahApps MetroWindow non-draggable

I've just started using MahApps with WPF. After converting my WPF Window to a MetroWindow it's no more locked. With standard WPF and the following settings
WindowStyle="None" ResizeMode="NoResize the window is not movable.
However with MetroWindow it is movable. I don't want users to be able to move the window around. How can I achieve this with MetroWindow?
As #Mathew said, you can set IsWindowDraggable property of your MetroWindow to false. A sample code can be like this:
<controls:MetroWindow
x:Class="MyNameSpace.Window1"
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:controls="http://metro.mahapps.com/winfx/xaml/controls"
IsWindowDraggable="False"
ResizeMode="NoResize"
WindowStyle="None"
ShowTitleBar="False"
>
.....
</controls:MetroWindow>

wpf borderless window focus not firing

I have the following WPF window definition but the focus/lost focus events are not firing when I click away from the application, any ideas?
<Window x:Class="BevaClient.windowMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:BevaClient"
xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="VPN Tool" Height="500" Width="370"
Focusable="True"
WindowStyle="None"
ResizeMode="NoResize"
Topmost="True"
Style="{StaticResource defaultWindow}"
Loaded="Window_Loaded"
GotFocus="Window_GotFocus"
LostFocus="Window_LostFocus">
I have tried setting topmost to false to see if this was the issue but it makes no difference.
Any advice on this issue would be very much appreciated.
Thanks,
David
Hook to Activated and Deactivated events instead.

Categories