2014-08-27 44 views
4

我創建了一個消息框用戶控件,角落的半徑如下圖所示,但是,我無法爲此用戶控件設置透明。請幫幫我。如何在wpf中爲用戶控件設置透明

非常感謝。

enter image description here

更新:

我已經爲你的指令來實現,但它仍然不是透明的,我覺得這樣的背景下的用戶控件是白色,請幫助我。以下是我的代碼:

<UserControl x:Class="Nanote.TestDialog" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      d:DesignHeight="200" 
      Height="200" Width="450" 
      d:DesignWidth="300" 
      mc:Ignorable="d"> 
    <Border CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
     Background="Transparent"> 
     <Rectangle Fill="White" Margin="10" /> 
    </Border> 
</UserControl> 
+0

請添加一些XAML你的問題,使得它更容易幫助。 – 2014-08-27 10:12:07

+0

你在使用邊框嗎? – Pragmateek 2014-08-27 10:24:31

+0

@Pragmateek:是的,請看我的代碼。 – admin 2014-08-28 02:11:21

回答

6

考慮以下XAML:

<Grid Background="Red"> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
    </Grid.RowDefinitions> 
    <Grid Margin="20"> 
     <Border CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
      Background="Transparent"> 
      <Rectangle Fill="White" /> 
     </Border> 
    </Grid> 
    <Grid Grid.Row="1" Margin="20"> 
     <Rectangle Fill="White" /> 
     <Border CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
      Background="Transparent" /> 
    </Grid> 
    <Border Grid.Row="2" CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
     Background="White" Margin="20"> 
     <Rectangle Fill="White" Margin="10" /> 
    </Border> 
</Grid> 

這將產生以下的輸出:

enter image description here

希望你現在可以制定出自己的解決方案這個例子。

+0

我試過按照你的例子,但它工作不正確。請參閱我的更新。 – admin 2014-08-28 02:11:00

+0

那麼如何將UserControl.Background設置爲'Transparent'呢? – Sheridan 2014-08-28 07:47:09

+0

它運作良好。謝謝。 – admin 2014-09-02 02:25:17

3

首先設置你的控制,以透明再加入邊框半徑(CornerRadius =「10」)的背景下,內部的邊框你把內容GRID

<Border BorderBrush="Black" BorderThickness="1,1,1,1" Background="White" CornerRadius="10,10,10,10"> 
<Grid ></Grid> 
</Border> 
相關問題