2009-02-03 25 views
9

Tôi có một cửa sổ không viền và trong suốt trong WPF, với một số trang trí lạ mắt ở dưới cùng. Có một chân trang tùy chỉnh với một số đường cong không thông thường và những gì không hiển thị logo của công ty. Cửa sổ này cần phải được thay đổi kích thước với một va li ở góc dưới cùng bên phải như cửa sổ thông thường.ẩn nắm giữ kích thước thay đổi mặc định trong wpf

Dù sao, tôi đã đặt ResizeGrip của riêng mình ở một vị trí thực sự ở chân, tuy nhiên độ bám mặc định vẫn hiển thị và nó đang trôi nổi trong không gian do cửa sổ vô hình.

Làm cách nào để ẩn ResizeGrip mặc định?

Trả lời

25

Sự xuất hiện của bộ điều chỉnh kích thước được điều khiển thông qua thuộc tính phụ thuộc ResizeMode trên Cửa sổ.

Nếu đây được thiết lập để 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> 

Window sẽ trông như thế này:

With Grip

Nếu nó được thiết lập để CanResize (mặc định):

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

Window sẽ trông như sau:

Can Resize

+1

Hình ảnh đã chết. –

+0

@SebastianNegraszus Tôi đã thêm một số mới. –

18

Vì vậy, để che giấu sự kìm kẹp mặc định, tôi ghi đè lên phong cách ResizeGrip mặc định như vậy mà nó là tầm nhìn bị che giấu. Dễ dàng với sự trợ giúp của 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> 

Sau đó, tôi thiết lập ResizeGrip của riêng mình trên trang trí cửa sổ tùy chỉnh với phong cách cầm tay mặc định.

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

Cảm ơn bạn đã lái xe bằng downvote jerk! – Jippers

+0

Tốt nhất. Cảm ơn Jippers. – Amsakanna

Các vấn đề liên quan