边框 WPF 中的标题



我需要在我的窗户周围放一个边框。

我可以将标题放在顶部的 35px 范围内吗?

<Window x:Class="LCDC.InterfazGrafica.frmModoDePago"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        SizeToContent="WidthAndHeight" FontSize="20"
        ResizeMode="NoResize"
        AllowsTransparency="True" WindowStyle="None"
        WindowStartupLocation="CenterScreen">
    <Border BorderBrush="#090A9E" BorderThickness="5,35,5,5">
            <Grid>
                ...
            </Grid>
    </Border>
</Window>

您可以为假标题保留 1 行网格。您需要一些隐藏的代码来使标题可拖动,以便用户可以通过将鼠标按住假标题并拖动它来移动窗口:

<Border BorderBrush="#090A9E" BorderThickness="5">
    <Grid>
       <Grid.RowDefinitions>
          <RowDefinition Height="35"/>
          <RowDefinition Height="*"/>
       </Grid.RowDefinitions>
       <TextBlock Name="tit" Text="{Binding Title, 
                         RelativeSource={RelativeSource AncestorType=Window}}"
                  VerticalAlignment="Center" Padding="35,0,0,0">
          <TextBlock.Background>
             <ImageBrush ImageSource="{Binding Icon, 
                           RelativeSource={RelativeSource AncestorType=Window}}" 
                   Viewport="2,2,30,30" ViewportUnits="Absolute"/>
          </TextBlock.Background>
       </TextBlock>
       <!-- other contents here, remember to put them in the second row -->
       <!-- ... -->
    </Grid>
</Border>

在代码隐藏中,使用以下代码使假标题可拖动:

//in your Window constructor
InitializeComponent();
tit.MouseLeftButtonDown += (s,e) => {
   DragMove();
};

如果你想在假标题周围有一些边框,只需在TextBlock周围包裹另一个边框并设置一些底部边框(因为左、右和上边框由外边框渲染)。

最新更新