wpf 父控件透明子控件不透明
2015-06-25 18:54
309 查看
在wpf开发中遇到子控件会继承父类控件属性的问题,
例如:
此时两个Label都会继承stackPanel的Opacity属性,如果想要不继承透明属性,这时候需要用到笔刷,代码如下:
例如:
<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>
相关文章推荐
- Codis集群部署测试
- hdu 4324 Triangle LOVE (targan判连通)
- 网络爬虫2--PHP/CURL库(client URL Request Library)
- Python——条件分支
- 性能测试之一----I/O读写速度(2)
- (译)Getting Started——1.3.3 Working with Foundation(使用Foundation框架)
- linux 添加、删除硬盘 mount/unmount
- 卸载oracle 11g数据库软件
- 从 IHTMLDocument2 获得/写入 HTML 文本 (IPersistStreamInit)
- Swift字典
- getDimension和getDimensionPixelSize的区别
- LintCode-最长公共子串
- HttpServletRequest类的getAttribute()方法与getParameter()方法的区别
- 好东西大家一起分享
- hdu 1269 迷宫城堡(tarjan判连通)
- python matplotlib 画心形线
- 简明 Python 编程规范
- Android WebView 获取网页的标题
- wireshark 配 filddler 手机抓包
- Oracle job procedure 存储过程定时任务(转自hoojo)