title: WPF XAML Local (child) styles are being overwritten. Why?
body: <p>I wrote a simple dialog (XAML/WPF) and a test app and the dialog looks fine. In particular the buttons in the ListView have rounded corners. I've posted a picture and the code below.
  The problem? When I use this dialog inside a much larger program (codebase too large to share), <strong>the rounded corners</strong> and other styling is gone.  I strongly suspect something in the larger program is taking precedence over my local work.  Perhaps a global style for buttons or some such thing?</p>
  <ol>
  <li>I'd like to understand what is going on. Presumably something in the main app takes precedence over my xaml work?</li>
  <li>I'd like to know if there is a way to say &quot;don't inherit styles from the app itself. Rather use WPF defaults unless I override them.&quot;, assuming that is the problem.</li>
  </ol>
  <p>See picture (notice rounded corners)</p>
  <p><a href="https://i.stack.imgur.com/dCO5H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dCO5H.png" alt="enter image description here" /></a></p>
  <p>See picture from when I call it from actual main application instead of test application</p>
  <p>Notice in particular lack of rounded corners. My work to produce rounded corners is gone! Also, in the test app, hovering over a button shows a blue color which I assume is default (I didn't do it). When called from main app, no such hover effect. I suspect the main app gets rid of that somewhere.</p>
  <p><a href="https://i.stack.imgur.com/f0MDE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f0MDE.png" alt="enter image description here" /></a></p>
  <p>Here's the simple dialog xaml</p>
  <pre><code>&lt;Window x:Class=&quot;FirmsDialog&quot;
               xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
               xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
               xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
               xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
               xmlns:local=&quot;clr-namespace:Dialogs&quot;
                  
               mc:Ignorable=&quot;d&quot; 
               d:DesignHeight=&quot;450&quot; d:DesignWidth=&quot;400&quot;
          Width=&quot;390&quot; Height=&quot;720&quot; BorderBrush=&quot;LightGray&quot;
          WindowStartupLocation=&quot;CenterScreen&quot; ResizeMode=&quot;NoResize&quot;
           x:Name=&quot;FirmsViewDlg&quot; Loaded=&quot;FirmsViewDlg_Loaded&quot;
          &gt;
  
      &lt;Window.Resources&gt;
          &lt;FontFamily x:Key=&quot;AvenirNextforCompany&quot;&gt;
              pack://application:,,,/Assets/Fonts/#AvenirNextforCompany
          &lt;/FontFamily&gt;
          &lt;local:ReverseObjectToBool x:Key=&quot;ReverseObjectToBoolConverter&quot; /&gt;
  
          &lt;local:ObjectToBool x:Key=&quot;ObjectToBoolConverter&quot; /&gt;
         
          
          
  
          
          &lt;!-- New style --&gt;
          &lt;Style x:Key=&quot;StyleListViewItem&quot; TargetType=&quot;ListViewItem&quot;&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property=&quot;IsMouseOver&quot; Value=&quot;True&quot;&gt;
                      &lt;Setter Property=&quot;Background&quot; Value=&quot;Green&quot;/&gt;
                  &lt;/Trigger&gt;
                  &lt;Trigger Property=&quot;IsSelected&quot; Value=&quot;True&quot;&gt;
                      &lt;Setter Property=&quot;Background&quot; Value=&quot;Blue&quot;/&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
              
          &lt;/Style&gt;
  
          &lt;!-- Existing style --&gt;
          &lt;Style x:Key=&quot;StyleListView&quot; TargetType=&quot;ListView&quot;&gt;
              &lt;Setter Property=&quot;ItemContainerStyle&quot; Value=&quot;{StaticResource StyleListViewItem}&quot;/&gt;
              &lt;Setter Property=&quot;SnapsToDevicePixels&quot; Value=&quot;true&quot;/&gt;
              &lt;!-- ... --&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid &gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height=&quot;Auto&quot;&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition Height=&quot;Auto&quot;&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition Height=&quot;*&quot;&gt;&lt;/RowDefinition&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width=&quot;*&quot;&gt;&lt;/ColumnDefinition&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;Label Grid.Row=&quot;0&quot; Content=&quot;Select Company&quot; HorizontalAlignment=&quot;Center&quot; FontSize=&quot;20px&quot; Foreground=&quot;#393a3d&quot; FontFamily=&quot;{StaticResource AvenirNextforCompany}&quot; FontWeight=&quot;Normal&quot;  &gt;&lt;/Label&gt;
          &lt;Label Grid.Row=&quot;1&quot; Content=&quot;Accountant companies&quot; Margin=&quot;10,0&quot; FontFamily=&quot;{StaticResource AvenirNextforCompany}&quot; FontSize=&quot;14px&quot; Foreground=&quot;#8d9096&quot; FontWeight=&quot;Normal&quot;&gt;&lt;/Label&gt;
          &lt;ListView  BorderThickness=&quot;0&quot; Grid.Row=&quot;2&quot; ItemsSource=&quot;{Binding RealmMembershipInfo}&quot;  SelectedItem=&quot;{Binding SelectedFirm}&quot;   x:Name=&quot;realmListBox&quot; 
                     HorizontalContentAlignment=&quot;Stretch&quot;  HorizontalAlignment=&quot;Stretch&quot; Height=&quot;Auto&quot; Margin=&quot;0,0,0,0&quot;
                     VerticalAlignment=&quot;Top&quot;  FontWeight=&quot;Bold&quot; FontSize=&quot;14&quot; Background=&quot;White&quot;              
                     ScrollViewer.HorizontalScrollBarVisibility=&quot;Disabled&quot;
                      BorderBrush=&quot;LightGray&quot;&gt;
              
              &lt;ListView.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Button  Click=&quot;Button_Click&quot; 
                         
                           MinHeight=&quot;65&quot; Padding=&quot;10,0,10,0&quot;
                          Margin=&quot;0,0,0,0&quot;            HorizontalContentAlignment=&quot;Left&quot; HorizontalAlignment=&quot;Stretch&quot;     BorderBrush=&quot;LightGray&quot;    Background=&quot;White&quot; Foreground=&quot;#393a3d&quot;  FontFamily=&quot;{StaticResource AvenirNextforCompany}&quot; FontSize=&quot;14px&quot; FontWeight=&quot;SemiBold&quot;
                              
                          &gt;
                          &lt;Button.Resources&gt;
                              &lt;Style TargetType=&quot;Border&quot;&gt;
                                  &lt;Setter Property=&quot;CornerRadius&quot; Value=&quot;9&quot;/&gt;
  
  
                              &lt;/Style&gt;
  
                          &lt;/Button.Resources&gt;
                          &lt;TextBlock Text=&quot;{Binding displayName}&quot;  TextWrapping=&quot;Wrap&quot; HorizontalAlignment=&quot;Stretch&quot;  Foreground=&quot;#393a3d&quot;  FontFamily=&quot;{StaticResource AvenirNextforCompany}&quot; FontSize=&quot;14px&quot; FontWeight=&quot;Bold&quot; &gt;
  
                          &lt;/TextBlock&gt;
  
                      &lt;/Button&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListView.ItemTemplate&gt;
  
              &lt;ListView.ItemContainerStyle&gt;
                  &lt;Style TargetType=&quot;ListViewItem&quot;&gt;
                      &lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;0&quot;/&gt;
                      &lt;Setter Property=&quot;Margin&quot; Value=&quot;10,10,10,10&quot;/&gt;
                      &lt;Setter Property=&quot;Padding&quot; Value=&quot;0&quot;/&gt;
                      &lt;Style.Triggers&gt;
                          &lt;Trigger Property=&quot;Control.IsMouseOver&quot; Value=&quot;True&quot;&gt;
                              &lt;Setter Property=&quot;Control.Background&quot; Value=&quot;Transparent&quot; /&gt;
                              &lt;Setter Property=&quot;BorderBrush&quot; Value=&quot;Transparent&quot; /&gt;
                              &lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;0&quot; /&gt;
                          &lt;/Trigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/ListView.ItemContainerStyle&gt;
          &lt;/ListView&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  <p>Simple program to show the Xaml above</p>
  <pre><code>using Dialogs;
  using Models;
  using System.Collections.Generic;
  using System.Windows;
  
  namespace TestApp
  {
     /// &lt;summary&gt;
     /// Interaction logic for MainWindow.xaml
     /// &lt;/summary&gt;
     public partial class MainWindow : Window
     {
        public MainWindow()
        {
           InitializeComponent();
        }
  
        private void Button_SelectFirm(object sender, RoutedEventArgs e)
        {
           // hack code to set up dialog
           RealmMembershipInfo realmInfo = new RealmMembershipInfo();
           realmInfo.realmMembershipInfo = new List&lt;RealmMembershipItem&gt;();
  
           RealmMembershipItem item = new RealmMembershipItem();
           item.displayName = &quot;Company 1&quot;;        
           realmInfo.realmMembershipInfo.Add(item);
  
           item = new RealmMembershipItem();
           item.displayName = &quot;Company2&quot;;         
           realmInfo.realmMembershipInfo.Add(item);
  
           
  
           FirmsDialog dlg = new FirmsDialog(realmInfo);
           dlg.ShowDialog();
           MessageBox.Show(&quot;Your picked firm: &quot; + dlg.SelectedFirm);
           
        }
  
        private void Button_SelectClient(object sender, RoutedEventArgs e)
        {
          
        }
     }
  }
  </code></pre>