2015-12-21 54 views
1

我想讓我的UserControl顯示圓角。UserControl中的圓角不顯示

這是我的標記:

<Border CornerRadius="10" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center" > 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="50" /> 
      <RowDefinition Height="20" /> 
      <RowDefinition Height="25" /> 
      <RowDefinition Height="25" /> 
      <RowDefinition Height="25" /> 
      <RowDefinition Height="25" /> 
      <RowDefinition Height="50" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="10" /> 
      <ColumnDefinition Width="220" /> 
      <ColumnDefinition Width="10" /> 
     </Grid.ColumnDefinitions> 
     <Grid.Background> 
      <ImageBrush ImageSource="{StaticResource NavyBlueGround}" /> 
     </Grid.Background> 
     <Label Grid.Column="1" Grid.Row="0" Style="{StaticResource GelTitle}" Content="Customer Search" VerticalAlignment="Bottom" HorizontalAlignment="Center"/> 
     <Label Grid.Row="1" Grid.Column="1" Style="{StaticResource GelCaption}" Content="Enter Customer First Name" VerticalAlignment="Bottom" /> 
     <TextBox Grid.Row="2" Grid.Column="1" Name="txtForeName" Background="White" VerticalContentAlignment="Center"/> 
     <Label Grid.Row="3" Grid.Column="1" Style="{StaticResource GelCaption}" Content="Enter Customer Last Name" VerticalAlignment="Bottom" /> 
     <TextBox Name="txtSurname" Grid.Column="1" Grid.Row="4" FontSize="14" Text="hello" VerticalContentAlignment="Center" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" /> 
     <Button Name="btnCustomerSearch" Grid.Column="1" Grid.Row="5" Style="{StaticResource GelButton}" Content="Search" Click="btnCustomerSearch_Click" VerticalAlignment="Center" /> 
    </Grid> 
</Border> 

,這是什麼樣子:

enter image description here

回答

3

而不是使用爲網格的背景下,將其用於您的邊框。

<Border CornerRadius="10" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center" > 
    <Border.Background> 
     <ImageBrush ImageSource="{StaticResource NavyBlueGround}" /> 
    </Border.Background> 

編輯:這樣做的原因的問題是,一個邊界(當填充= 5)設置其子的邊緣5個像素中還限定CornerRadius設置網格的邊緣在更進一步。

因此,網格(及其背景)的邊界不是發生圓角的地方。

+0

看起來很有希望我會盡快回復。謝謝 –

+1

很好的答案,這麼簡單。我承認我仍然習慣WPF,但我學得越多,我越喜歡WinForm。謝謝 –

+0

謝謝。我也更新了這篇文章,以澄清 –

1

你必須有別的事情正在進行。我用UserControl將你的代碼粘貼到一個新項目中,並且渲染正常。

Example Image

你能提供,如果一個新的項目不起作用同樣的話,和比較的差異,以幫助解決更詳細?

+0

嗨,謝謝你在這裏的所有時間。我接受了一個更簡單的答案。關於你的理論,我傾向於同意你的觀點。我爲內部元素使用樣式,但決不會影響邊框,所以它必須是對可能會影響外部邊框的內部元素使用樣式的'事情'。我接受的答案消除了這一點;窘境'非常感謝你評論/回答 –

+0

它呈現給你很好,因爲你也設置了邊框的背景:) –