我的情况如下.
我有一个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">
...
Run Code Online (Sandbox Code Playgroud)
但是,我想将一些样式添加到另一个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>
Run Code Online (Sandbox Code Playgroud)
所以,我想要做的是在App.xaml中将基本设计的样式定义为默认样式.然后,添加一些修改,例如添加上下文菜单,从每个xaml添加事件.
但是,通过上面的实现,App.xaml中定义的样式将被Window.xaml中定义的样式覆盖.
有没有办法解决问题并实现它?
风格有一个BasedOn属性:
<Style x:Key="Style1">
...
</Style>
<Style x:Key="Style2" BasedOn="{StaticResource Style1}">
...
</Style>
Run Code Online (Sandbox Code Playgroud)
顺便说一下:<Style x:Key="{x:Type ListViewItem}"看起来有点奇怪.本x:Key应在XAML字典中的唯一键-通常是一个字符串.
| 归档时间: |
|
| 查看次数: |
5298 次 |
| 最近记录: |