【问题标题】:hide the default resize grip in wpf隐藏 wpf 中的默认调整大小夹点
【发布时间】:2010-10-05 02:00:44
【问题描述】:

我在 WPF 中有一个无边框透明窗口,底部有一些花哨的装饰。有一个带有一些非常规曲线的自定义页脚,并且没有显示公司徽标。这个窗口需要像传统窗口一样通过右下角的手柄来调整大小。

无论如何,我已经将我自己的 ResizeGrip 放在了实际上在页脚上的位置,但是默认夹点仍然显示并且由于不可见窗口而在空间中浮动。

如何隐藏默认的 ResizeGrip?

【问题讨论】:

    标签: wpf resizegrip


    【解决方案1】:

    调整大小夹点的外观是通过 Window 上的 ResizeMode 依赖属性控制的。

    如果设置为 CanResizeWithGrip:

    <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="50" Width="150" 
            WindowStyle="None" AllowsTransparency="True" Background="#19FFFFFF"
            ResizeMode="CanResizeWithGrip">
        <Grid></Grid>
    </Window>
    

    窗口将如下所示:

    如果设置为CanResize(默认):

    <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="50" Width="150" 
            WindowStyle="None" AllowsTransparency="True" Background="#19FFFFFF"
            ResizeMode="CanResize">
        <Grid></Grid>
    </Window>
    

    窗口如下所示:

    【讨论】:

    • @SebastianNegraszus 我添加了一些新的。
    【解决方案2】:

    所以为了隐藏默认夹点,我覆盖了默认的 ResizeGrip 样式,使其可见性被隐藏。借助 Expression Blend 2 轻松实现。

    <Style TargetType="{x:Type ResizeGrip}">
        <Setter Property="MinWidth" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
        <Setter Property="MinHeight" Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ResizeGrip}">
                    <Grid SnapsToDevicePixels="True" Background="{TemplateBinding Background}">
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Visibility" Value="Hidden"/>
    </Style>
    

    然后我在自定义窗口装饰上设置我自己的 ResizeGrip,其样式与默认夹点样式相同。

    <SolidColorBrush x:Key="ResizeGripperForeground" Color="#B8B4A2"/>
    <Style x:Key="VisibleResizeGrip" TargetType="{x:Type ResizeGrip}">
        <Setter Property="MinWidth" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
        <Setter Property="MinHeight" Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ResizeGrip}">
                    <Grid SnapsToDevicePixels="True" Background="{TemplateBinding Background}">
                        <Path Fill="White" HorizontalAlignment="Right" Margin="0,0,2,2" VerticalAlignment="Bottom" Data="M 8,0 L 10,0 L 10,2 L 8,2 Z M 4,4 L 6,4 L 6,6 L 4,6 Z M 8,4 L 10,4 L 10,6 L 8,6 Z M 0,8 L 2,8 L 2,10 L 0,10 Z M 4,8 L 6,8 L 6,10 L 4,10 Z M 8,8 L 10,8 L 10,10 L 8,10 Z"/>
                        <Path Fill="{StaticResource ResizeGripperForeground}" HorizontalAlignment="Right" Margin="0,0,3,3" VerticalAlignment="Bottom" Data="M 8,0 L 10,0 L 10,2 L 8,2 Z M 4,4 L 6,4 L 6,6 L 4,6 Z M 8,4 L 10,4 L 10,6 L 8,6 Z M 0,8 L 2,8 L 2,10 L 0,10 Z M 4,8 L 6,8 L 6,10 L 4,10 Z M 8,8 L 10,8 L 10,10 L 8,10 Z"/>
            <Path Data="M8,0L10,0 10,2 8,2z M4,4L6,4 6,6 4,6z M8,4L10,4 10,6 8,6z M0,8L2,8 2,10 0,10z M4,8L6,8 6,10 4,10z M8,8L10,8 10,10 8,10z" Fill="White" HorizontalAlignment="Right" Margin="0,0,2,2" VerticalAlignment="Bottom" />
            <Path Data="M8,0L10,0 10,2 8,2z M4,4L6,4 6,6 4,6z M8,4L10,4 10,6 8,6z M0,8L2,8 2,10 0,10z M4,8L6,8 6,10 4,10z M8,8L10,8 10,10 8,10z" Fill="{StaticResource ResizeGripperForeground}" HorizontalAlignment="Right" Margin="0,0,3,3" VerticalAlignment="Bottom" />
          </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多