c# – 按钮样式的内容仅出现在一个Button实例中
发布时间:2020-12-16 01:21:22 所属栏目:百科 来源:网络整理
导读:我有一个Viewbox: Viewbox x:Key="SampleViewbox" Grid Ellipse Stroke="#e2e2e0" StrokeThickness="6" Fill="#d5273e" Width="128" Height="128"/ /Grid/Viewbox 然后我将其包含在样式中: Style x:Key="SampleStyle" TargetType="{x:Type Button}" Setter
我有一个Viewbox:
<Viewbox x:Key="SampleViewbox" > <Grid> <Ellipse Stroke="#e2e2e0" StrokeThickness="6" Fill="#d5273e" Width="128" Height="128"/> </Grid> </Viewbox> 然后我将其包含在样式中: <Style x:Key="SampleStyle" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="Transparent" > <ContentPresenter Content="{StaticResource SampleViewbox}"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> 现在我使用SampleStyle创建了许多按钮 <Grid> <StackPanel> <Button Style="{StaticResource SampleStyle}" Height="50" Width="50"></Button> <Button Style="{StaticResource SampleStyle}" Height="80" Width="80"></Button> <Button Style="{StaticResource SampleStyle}" Height="20" Width="20"></Button> </StackPanel> </Grid> 但是,只有一个按钮具有椭圆(视图框) 如何让所有按钮都显示/显示椭圆? 解决方法
Viewbox是FrameworkElement,不能属于多个父项.每次按钮请求资源{StaticResource SampleViewbox}时,它们都会获得相同的实例.
要更改该行为,请添加x:Shared =“False”属性 <Viewbox x:Key="SampleViewbox" x:Shared="False"> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – Ruby:冻结数组中的字符串是否也应单独冻
- c# – 使用XElement保存XML文件时,文件中的对齐也会发生变化
- 正则表达式的匹配字符
- c – 如何在MacOSX中设置线程名
- oracle: local_listener,remote_listener,listener_network
- c# – RED5媒体服务器或任何其他带.NET API的跨平台媒体服务
- VB小程序:生成十个不重复的随机数
- c# – 预定义类型和自定义类型之间的“对称性”是什么意思?
- PostgreSQL:运行查询行的计数“分钟”
- 在swift中思考C#protected accessor的正确方法是什么?