My situation is similar to the following.
I have an App.xaml that includes Style for a ListView, like this:
<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"> ...
However, I want to add some styles to another xaml, say in Window.xaml, like this:
<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>
So what I want to do is define the base design style in App.xaml as the default style. Then add some changes, such as adding a context menu, adding events from each xaml.
But, with the above implementation, the style defined in App.xaml will be overwritten with the style defined in Window.xaml.
Is there a way to solve the problem and achieve it?
source share