相关疑难解决方法(0)

在WPF中,有没有办法将两个Style组合成一个控件?

我的情况如下.

我有一个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中定义的样式覆盖.

有没有办法解决问题并实现它?

wpf xaml styles

6
推荐指数
1
解决办法
5298
查看次数

标签 统计

styles ×1

wpf ×1

xaml ×1