边界WPF中的标题

时间:2014-11-14 01:34:16

标签: c# wpf xaml

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

我可以将标题放在顶部的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 个答案:

答案 0 :(得分:0)

您可以为假标题保留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>

在codebehind中,使用此代码使假标题可拖动:

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

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