在wpf中隐藏默认的大小调整符

本文关键字:调整 默认 wpf 隐藏 | 更新日期: 2023-09-27 17:51:13

是否可以在wpf中隐藏默认的调整手柄,我有一个没有手柄的自定义窗口,目前正在使用:

<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>

我知道这是可能的只是改变ResizeMode="CanResize",但这是唯一的方法来调整窗口的大小,我能想到的

在wpf中隐藏默认的大小调整符

是的,您可以从窗口中取出默认的大小调整握把。您需要重写WindowTemplate。下面是在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>

Border将包含你需要在窗口中显示的所有内容(例如文本框)。如果你想自定义ResizeGrip你也可以定义它。