2015-05-15 109 views
1

我正在創建一個自定義加載消息,我想僅將背景設置爲半透明。我遇到的問題是整個堆疊面板設置爲半透明,包括背景和前景。我如何才能使背景變得半透明,並且讓前景保持原樣?以下是我的xaml代碼。如何設置半透明背景,但不是前景的WP8?

 <StackPanel Grid.Row="0" x:Name="spLoading" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent"> 
      <Border Margin="5" Padding="5" BorderThickness="1" BorderBrush="Black" Background="Black" Opacity=".1" CornerRadius="10"> 
       <TextBlock x:Name="txtLoading" Foreground="White" Text="loading . . ." HorizontalAlignment="Center" TextAlignment="Center" FontSize="30" FontWeight="Bold" Padding="5" /> 
      </Border>     
     </StackPanel> 

回答

0

如果我沒有理解好你想要的是邊框的背景有somekind的不透明性,做到這一點的方法是使用像邊框的背景的alpha通道發揮:

<Border Background="#3000"...> 

<Border Background="#33000000"...> 

您可以在顏色在任何地方使用,你的情況:

<StackPanel Grid.Row="0" x:Name="spLoading" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent"> 
     <Border Margin="5" Padding="5" BorderThickness="1" BorderBrush="#33000000" Background="#33000000" CornerRadius="10"> 
      <TextBlock x:Name="txtLoading" Foreground="White" Text="loading . . ." HorizontalAlignment="Center" TextAlignment="Center" FontSize="30" FontWeight="Bold" Padding="5" /> 
     </Border> 
    </StackPanel> 

有了,你有邊框背景和中風半透明

+0

實際上,我只是想要「加載」具有純色,但其他一切都是半透明的。 – amarankes

+0

我認爲代碼應該是這樣的,但不知道什麼是正確的synatx。 裏面的一些邏輯 amarankes

+0

你的意思是說像我添加的邊框的中風和背景? –

0
<Grid Grid.Row="0"> 
     <Rectangle Opacity="0.4" Fill="Black"></Rectangle> 
     <StackPanel Background="White" HorizontalAlignment="Center" VerticalAlignment="Center" > 
      <TextBlock Margin="20,10,20,10">Loading...</TextBlock> 
     </StackPanel> 
    </Grid> 

這裏做的事情,是網格取足可用空間,長方形爲您提供了灰階(不透明),以及StackPanel中只是按原樣工作。

(注意這是我在WPF中做的)

3

這會做必需的。

<Border Margin="5" Padding="5" BorderThickness="1" BorderBrush="Black" CornerRadius="10"> 
      <Border.Background> 
       <SolidColorBrush Color="Black" Opacity="0.1" /> 
      </Border.Background> 
      <TextBlock /> 
</Border> 
+0

是的,這是我正在尋找,但無法弄清楚語法。謝謝! – amarankes

+0

歡迎您:)。如果這回答你的問題,你應該將其標記爲答案,以便其他人也可以從中獲得幫助。 –