wpf - wpf中的多种样式
问题描述
我想TextBox
从静态资源中定义我的设计,如何应用它?
现在我有:
<TextBox Style="{StaticResource TextBoxHeight }" />
在这里Page.Resources
:
<Page.Resources>
<Style x:Key="TextBoxHeight" TargetType="{x:Type TextBox}" >
<Setter Property="Height" Value="20"/>
</Style>
<Style x:Key="TextBoxBorder" TargetType="{x:Type Border}" >
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Page.Resources>
但我需要:
<TextBox Style="{StaticResource TextBoxHeight }" Style="{StaticResource TextBoxBorder }" />
但它给出了错误“属性'样式'被设置多次”
解决方案
您不能Style
多次设置该属性。而且您不能将 aStyle
与 aTargetType
应用于Border
a TextBox
。Border
但是在样式Resources
字典中添加隐式Button
样式应该可以:
<Style x:Key="TextBoxHeight1" TargetType="{x:Type TextBox}" >
<Setter Property="Height" Value="20"/>
<Style.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Style.Resources>
</Style>
推荐阅读
- regex - 将字符串转换为正则表达式模式
- json - 从数组和对象中提取字段的值
- html - 如何使用 javascript 和递归查询嵌套级别 DOM
- javascript - 如何修复'在猫头鹰轮播中的图像之间切换内容移动到顶部'
- javascript - 窗口加载未显示正确的其他消息
- angular - 新的 Angular 项目无法正确渲染
- excel - 使用 Excel VBA 从两个列表中构建一个列表
- wordpress - 匹配 htaccess 重定向
- swift - 如何在 SwiftUI 中的 TabView 的 tabItem 上显示徽章编号?
- c++ - Memset 没有填满整个指针数组 c++