我的情况如下。
我有一个 App.xaml,其中包含 ListView 的样式,如下所示:
<Style x:Key="{x:Type ListViewItem}" TargetType="ListViewItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
...
但是,我想将一些样式添加到另一个 xaml 中,让我们在 Window.xaml 中这样说:
<ListView AlternationCount="2" Background="#FFECECEC">
<ListView.Resources>
<Style x:Key="{x:Type ListViewItem}" TargetType="{x:Type ListViewItem}">
<EventSetter Event="PreviewMouseDoubleClick" Handler="OnPreviewMouseDoubleClick" />
</Style>
</ListView.Resources>
</ListView>
因此,我想要做的是将 App.xaml 中的基本设计的样式定义为默认样式。
然后,添加一些修改,例如添加上下文菜单、添加每个 xaml 中的事件。
但是,通过上述实现,App.xaml 中定义的 Style 将被 Window.xaml 中定义的 Style 覆盖。
有没有什么办法可以解决这个问题并实现它?
款式有BasedOn
财产:
<Style x:Key="Style1">
...
</Style>
<Style x:Key="Style2" BasedOn="{StaticResource Style1}">
...
</Style>
Btw: <Style x:Key="{x:Type ListViewItem}"
似乎有点奇怪。这x:Key
应该是 xaml 字典中的唯一键 - 通常是字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)