2012-10-17 100 views
0

我是新來WPF。我的要求是做一個圓角矩形的啓動畫面。我做了一些搜索並實現了圓形矩形。但問題在於它失敗了一些領域。請看截圖並查看下面的代碼。 enter image description here邊框不是覆蓋整個區域

中的圖像,你可以看到黑色邊框拐角處

打破這是我的XAML

<Window x:Class="TimeLogger.StartWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Width="470" Height="270"  ShowInTaskbar="False" WindowStartupLocation="CenterScreen" 
     ResizeMode="NoResize" WindowStyle="None" AllowsTransparency="True" Background="Transparent" > 
    <Border BorderBrush="#FF000000" BorderThickness="2,2,2,2" CornerRadius="8,8,8,8"> 
     <Grid Background="#012a7a" > 
      <Label Margin="-5,-7,5,7"> 
       <TextBlock Foreground="Black" FontFamily="Segoe UI" FontSize="25" FontStretch="UltraExpanded" Height="71" Width="177"> 
        TimeLogger 
       </TextBlock> 
      </Label> 
     </Grid> 
    </Border> 
</Window> 
+0

爲什麼你把一個文本塊,在一個標籤? –

+0

@eranotzap。我需要在標籤中顯示一些文本,我需要實現相當於「 kbvishnu

+1

回答

1

應用角半徑爲邊界,使得它的外切不收縮邊框的內容的大小。您看到邊框頂部的網格繪畫,因爲它仍然填充邊框所說的可用區域。修復相當簡單:

  1. 在您的邊框而不是網格上設置背景顏色。保持網格透明。
  2. 應用填充到邊境或保證金的網格,以便離開房間外加圓角半徑。玩確切的價值,直到你得到你喜歡的東西。

事情是這樣的:

<Border 
    BorderBrush="#FF000000" 
    Background="#012a7a" 
    BorderThickness="2" 
    CornerRadius="8" 
    Padding="5" 
    > 
    <Grid> 
     <!-- In a code review, I'd question the value of negative margin on this label --> 
     <Label Margin="-5,-7,5,7"> 
      <TextBlock Foreground="Black" FontFamily="Segoe UI" FontSize="25" FontStretch="UltraExpanded" Height="71" Width="177"> 
       TimeLogger 
      </TextBlock> 
     </Label> 
    </Grid> 
</Border> 
1

我看到你的問題。

Border s爲偉大的事情。它們重量輕,對外觀有很大的控制能力。 的問題是,你給你的Grid一個Background顏色,而你應該給它你Border通常情況下,網格不會製作好樣式,尤其是當您在此處使用邊框時。網格非常適合從簡單到複雜的佈局,偶爾給它們一個Background是有道理的,但它幾乎總是最適合佈局。

只要複製粘貼此:

<Border BorderBrush="#FF000000" Background="#012a7a" BorderThickness="2,2,2,2" CornerRadius="8,8,8,8"> 
    <Grid> 
     <Label Margin="-5,-7,5,7"> 
      <TextBlock Foreground="Black" FontFamily="Segoe UI" FontSize="25" FontStretch="UltraExpanded" Height="71" Width="177"> 
       TimeLogger 
      </TextBlock> 
     </Label> 
    </Grid> 
</Border> 
+0

謝謝你的回答 – kbvishnu

0

邊境是一個內容控件中,但它TextBlock的

<Border Background="#012a7a" BorderBrush="#FF000000" Margin ="6" BorderThickness="4" CornerRadius="8,8,8,8"> 
    <TextBlock Foreground="Black" Margin="-5,-7,5,7" Height="71" Width="177" 
       VerticalAlignment="Center" HorizontalAlignment="Center" 
       FontFamily="Segoe UI" FontSize="25" FontStretch="UltraExpanded" 
       Text="TimeLogger" /> 
</Border>