首页 > Windows开发 > 详细

wpf 父控件透明子控件不透明

时间:2015-06-25 20:50:30      阅读:267      评论:0      收藏:0      [点我收藏+]

在wpf开发中遇到子控件会继承父类控件属性的问题,

例如:

<StackPanel  Orientation="Horizontal" Grid.Row="1" Background="Black" Opacity="0.3">
                                            <Label Content="{Binding Id}"  Foreground="White"  VerticalAlignment="Center"></Label>
                                            <Label Content="{Binding Name}" Foreground="White" VerticalAlignment="Center"></Label>
                                        </StackPanel>

此时两个Label都会继承stackPanel的Opacity属性,如果想要不继承透明属性,这时候需要用到笔刷,代码如下:

<SolidColorBrush Color="Black" Opacity=".3" x:Key="OpacityBrush"/>

<StackPanel  Orientation="Horizontal" Grid.Row="1" Background="{StaticResource OpacityBrush}">
                                            <Label Content="{Binding Id}"  Foreground="White"  VerticalAlignment="Center"></Label>
                                            <Label Content="{Binding Name}" Foreground="White" VerticalAlignment="Center"></Label>
                                        </StackPanel>

 

wpf 父控件透明子控件不透明

原文:http://www.cnblogs.com/smdm/p/4600690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!