英文:
Style based on default style MAUI
问题
我有一个所有Label
默认样式
<Style TargetType="Label">
<Setter ...
</Style>
然后我有一个带有x:Key
的Label
样式
<Style x:Key="notForAll" TargetType="Label">
<Setter ...
</Style>
所以,如果我这样做
<Label Style="{StaticResource notForAll}"/>
这个标签将不包括默认的标签样式,只有notForAll
样式。
如何以default
标签样式为基础创建notForAll
样式?我不能将默认样式放入BasedOn
<Style x:Key="notForAll" TargetType="Label" BasedOn="{StaticResource ????????????}">
<Setter ...
</Style>
我找到了WPF的解决方案
<Style x:Key="NamedStyle" TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
<Setter ...
</Style>
但这不适用于MAUI。
英文:
I have default style for all Label
<Style TargetType="Label">
<Setter ...
</Style>
Then I have style with x:Key
for Label
<Style x:Key="notForAll" TargetType="Label">
<Setter ...
</Style>
So, if i do this
<Label Style="{StaticResource notForAll}"/>
This label will not include default label style, only notForAll
style.
How can I base notForAll
style on default
label style? I can`t put default style into BasedOn
<Style x:Key="notForAll" TargetType="Label" BasedOn="{StaticResource ????????????}">
<Setter ...
</Style>
I found solution for WPF
<Style x:Key="NamedStyle" TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
<Setter ...
</Style>
But it doesn't work for MAUI.
答案1
得分: 3
样式继承说:
> 隐式样式可以从显式样式派生,但显式样式不能从隐式样式派生。
我认为你需要这样做:
<Style x:Key="commonLabelStyle" TargetType="Label">
<Setter ...
</Style>
<Style TargetType="Label" BasedOn="{StaticResource commonLabelStyle}">
<Setter ...
</Style>
<Style x:Key="notForAll" TargetType="Label" BasedOn="{StaticResource commonLabelStyle}">
<Setter ...
</Style>
英文:
Style inheritance says:
> An implicit style can be derived from an explicit style, but an explicit style can't be derived from an implicit style.
I think that you have to do something like this:
<Style x:Key="commonLabelStyle" TargetType="Label">
<Setter ...
</Style>
<Style TargetType="Label" BasedOn="{StaticResource commonLabelStyle}">
<Setter ...
</Style>
<Style x:Key="notForAll" TargetType="Label" BasedOn="{StaticResource commonLabelStyle}">
<Setter ...
</Style>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论