【发布时间】:2011-06-11 00:22:18
【问题描述】:
我的情况如下。
我有一个 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 中定义的样式将被 Window.xaml 中定义的样式覆盖。
有什么办法可以解决问题并实现吗?
【问题讨论】: