如果有这样的多个样式:
<Style TargetType="{x:Type local:MyControl}"> ...是从资源字典中合并而来的,这些资源字典的目标应该是相同类型的控制,应该优先考虑,它是第一种遇到的还是最后一种?
我在哪里可以找到管理这些事情的规则?
If there are multiple styles like this:
<Style TargetType="{x:Type local:MyControl}"> ...that are merged in from resource dictionaries that target the same type of control, which should have precedence, is it the first style encountered or last one?
Where can I find the rules that govern such things?
最满意答案
从最接近相关控件的ResourceDictionary应用样式。 一个例子:
<Window> <Window.Resource> <Style 1/> <Window.Resources> <Grid> <Grid.Resources> <Style 2/> </Grid.Resources> <TextBox/> </Grid> </Window>在上面的例子中,样式2将应用于TextBox。 如果希望级联样式(将两种样式应用于TextBox),可以使用BasedOn="{StaticResource {x:Type TextBox}}" Style2上的BasedOn设置为指向Style1。 请检查语法,我没有在这里VS。
正如你所看到的,这个类型变成了Key 。 由于不允许在一个ResourceDictionary具有两个具有相同键的元素,因此无法合并两个具有重叠样式的ResourceDictionaries。 应该可以围绕这样的需求进行设计,记住ResourceDictionary可以引用其他用途。 再次,您使用BasedOn 。
Styles are applied from the ResourceDictionary closest to the control in question. An example:
<Window> <Window.Resource> <Style 1/> <Window.Resources> <Grid> <Grid.Resources> <Style 2/> </Grid.Resources> <TextBox/> </Grid> </Window>In the above example, Style 2 will be applied to the TextBox. Should you wish to cascade the styles (apply both styles to the TextBox), you can set BasedOn on Style2 to point to Style1 using BasedOn="{StaticResource {x:Type TextBox}}". Please check the syntax, I don't have VS here.
As you can see, the type becomes the Key. Since it is not permissible to have two elements with the same key in a single ResourceDictionary, you cannot merge two ResourceDictionaries with overlapping styles. It should be possible to design around such a requirement, remembering that a ResourceDictionary can reference another use. Again, you use BasedOn.
更多推荐
应该,MyControl,字典,Type,电脑培训,计算机培训,IT培训"/> <meta name="descript
发布评论