Hide the default resizegrip in wpf - c#

Is it possible to hide the default resize grip in wpf, I have a custom window without handles on the sides and are currently using:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="100" Width="200" ResizeMode="CanResizeWithGrip">
<Grid></Grid>
</Window>
I know it's possible to just change ResizeMode="CanResize" but this is the only way to resize the window that I can think of.

Yes you can take out the default resize grip from the Window. You need to override the WindowTemplate. Here is how you would do in XAML:
<Window x:Class="MyNamespace.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True">
<Window.Template>
<ControlTemplate>
<Border>
</Border>
</ControlTemplate>
</Window.Template>
</Window>
Within the "Border" will go everything that you need to display in the Window (e.g. a TextBox). Then if you want your custom ResizeGrip you can define that as well. Hope this helps.

Related

How to resize content when maximize window in WPF?

I have this window and I would like to resize content ( fit it to the size of window ) when the user maximize this window , I've tried many solutions but any of them worked for me :
<Window x:Class="Window_Image"
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"
mc:Ignorable="d"
d:DesignHeight="550" d:DesignWidth="550">
<Grid>
<DockPanel LastChildFill="True" Name="ImgDock" Background="Transparent" >
<Image Source="../res/myimage.png" Width="450" Height="450" x:Name="ImageComp" Visibility="Visible" >
</Image>
</DockPanel>
</Grid>
One of solution that I've tried :
https://stackoverflow.com/a/47990733/19442413
Unfortunatly , this solution didn't works for me.
The issue was that the Image size was hardcoded (Height and Width properties).
By default, most of WPF's component will adjust their size to fill their containers.

WPF window with WindowChrome resizing issue

Have this simple XAML for a custom window. It works fine except during a resize (from the left, top, top-left and bottom-left) it looks awful. The window flashes like crazy. Doesn't seem like an OS issue as Microsoft's glass Windows app resize smooth as butter.
I'm trying to customize the window frame, but unless I use WindowChrome, I lose all the resizing, dragging, etc.
<Window x:Class="WpfApp2.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:WpfApp2"
WindowStyle="None"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="MainWindow" Height="450" Width="600">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="1,1,1,1" />
</WindowChrome.WindowChrome>
<Border BorderBrush="Red" BorderThickness="1">
<Button Content="Test" Height="25" Width="75" />
</Border>
</Window>

Grid Container resize with height and width specified - C# WPF Anchoring

When using Margins to specify top/left/bottom/right positions, the location of my button and inner grids is not what I expected with the following xaml:
<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="WpfApplication1.MainWindow"
Title="Dialog" WindowStartupLocation="CenterScreen" ResizeMode="CanResize" Height="399" Width="590">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 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:sys="clr-namespace:System;assembly=mscorlib" x:Name="TopÆLeftÆRight596" Background="#FFFFFF">
<Grid Margin="150, 85, 153, 110" x:Name="Panel597" Background="#EEEEEE">
<Button Margin="97,77,108,101" x:Name="BLANK_BUTTON598" ToolTip="Blank" Cursor="Arrow" FontFamily="Arial" FontSize="12" FontWeight="Normal" Foreground="#000000" Content="Blank" />
</Grid>
</Grid>
I believe what is happening is that because my container grid is set to stretch (x:Name="TopÆLeftÆRight596"), the margins are calculated off the window which includes the title bar. If I set height and width on that grid, resizing of the inner controls is no longer possible.
I need a way to specify the height/width values on the window, or perhaps another type of container, so that the margin calculations do not include the title bar, and the inner contents grow and shrink when the window is resized.
Please keep in mind I have no control over the left/top/right/bottom margin values provided.
In essence, what I'm trying to do is duplicate top/left/bottom/right anchoring of the Grid(x:Name="Panel597") and Button(x:Name="BLANK_BUTTON598") controls.
Any help is greatly appreciate. Thanks.

How to set a resize limit for a window?

Lets say I have a xaml for my window like this:
<Window x:Class="WavePoint_MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontSize="13"
FontFamily="Verdana"
xmlns:local="clr-namespace:WavePoint_MVVM"
Height="{Binding SystemParameters.PrimaryScreenHeigth}"
Width="{Binding SystemParameters.PrimaryScreenWidth}"
AllowsTransparency="False"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResizeWithGrip"
<Grid/>
</Window>
Now I want to fix some sort of limit in which the user can't resize the window beyond it. Just to give an example, in Spotify app for Windows desktop, the user can't resize beyond a certain limit. This is the minimum I can get:
Thoughts?
To force a minimum window size, set your MinWidth and MinHeight attributes on the Window:
<Window x:Class="WavePoint_MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontSize="13"
FontFamily="Verdana"
xmlns:local="clr-namespace:WavePoint_MVVM"
Height="{Binding SystemParameters.PrimaryScreenHeigth}"
Width="{Binding SystemParameters.PrimaryScreenWidth}"
AllowsTransparency="False"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResizeWithGrip"
MinWidth="640"
MinHeight="480">
<Grid/>
</Window>

Making an application with semi-transparent window and "transparent input"

I want to make an application with transparent window. I want to put one picture at the background of this window and make window transparent for inputs (i.e. if I click at window, it will be same as if I click there at screen if there is no this application). I want to make input box at application startup for input alpha. Is it possible to make an application like this one in c#? If yes, what is the best way to do this?
You can create a transparent window by the below XAML code in a WPF application. You can vary the opacity values between 0 and 1 to get the desired transparency. To get full transparency use 0.
<Window x:Class="WpfApplication3.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"
AllowsTransparency="True" WindowStyle="None" IsActive="False">
<Window.Background>
<SolidColorBrush Opacity="0.5" Color="White"/>
</Window.Background>
<Grid>
<TextBox Width="200" Height="50"/>
</Grid>
</Window>

Categories

Resources