2015-05-15 196 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

欢迎您:)。如果这回答你的问题,你应该将其标记为答案,以便其他人也可以从中获得帮助。 –