WPF Borderless window resize

烂漫一生 提交于 2019-12-01 03:31:05

Maybe it is simpler to assign WindowChrome.As per your comment you must be able to resize from all the sides as well as using grip.You can do all this by setting the WindowStyle to None and ResizeMode to CanResizeWithGrip or CanResize (whatever you wish to acheive)

<Window x:Class="MVVMProtoType.View.Test.Test"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Test" Height="300" Width="300" WindowStyle="None" AllowsTransparency="False" ResizeMode="CanResizeWithGrip">

In the code behid you must set the Window Chrome for the window . You can do it like this :

WindowChrome.SetWindowChrome(this, new WindowChrome());

OR You can use setter for window style like :

<Setter Property="WindowChrome.WindowChrome">
        <Setter.Value>
            <WindowChrome CornerRadius="0" GlassFrameThickness="1" UseAeroCaptionButtons="False"/>
        </Setter.Value>
</Setter>

MSDN link for more information

Please note WindowChrome class is a part of .NET 4.5 Framework. For.NET 4.0 users check out archive.msdn.microsoft.com/WPFShell

Fernando Aguirre

I wrote a solution in an other post, you can resize the window, you need to use .NET 4.5 or WPFShell

You can also put the WindowChrome code directly on your MainWindow.xaml like this, and it works perfectly without putting a setter.

<Window x:Class="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:Concursos"
    mc:Ignorable="d"
    Title="Concuros" Height="350" Width="525"
    WindowStyle="None"
    WindowState="Normal" 
    ResizeMode="CanResize"
    >
<WindowChrome.WindowChrome>
    <WindowChrome 
        CaptionHeight="0"
        ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>

    <Grid>

    <YOUR CODE HERE

</Grid>

You can go here to view the complete post.

Solution

Here is the before and after

Well this was a stupid mistake. I forgot to add handled = true; before I returned the result. Now the window is functioning as normal. As a note if you set the ResizeMode to NoResize this code won't work at all.

I also provided source code to a fully working (sizable, etc) WPF borderless window, that you might be interested in. It can be found here.

WPF Borderless Window issues: Aero Snap & Maximizing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!