2014-11-14 86 views
-1

我需要把我的窗口周圍的邊框。標題邊框WPF

我可以在頂部的35像素內放置一個標題嗎?

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

該邊框可以很容易地被另一個控件覆蓋。我認爲'Border'控件中沒有任何東西可以幫助你。 – BradleyDotNET

+0

是的,我使用WindowStyle =「無」 – avechuche

+0

嗯......好的。不知道爲什麼相關(除了刪除最初的邊框)。你仍然可以在自己的*邊框上覆蓋任何你想要的東西。 – BradleyDotNET

回答

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> 

在代碼隱藏,使用這個代碼,以使假標題拖動:

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

如果你想周圍的假標題一些邊境,只是包裝的TextBlock各地的另一邊界,只是設置一些底部邊框(因爲左,右和上邊框由外部邊框渲染)。