title: WPF Button IsEnabled Based on ComboBox Selection Overwriting default style
body: <p>I have a Button that is looking at 2 comboboxes to make sure they have a value before it is enabled.  The problem is the way I am doing it is overwriting the default style declared in my theme project.</p>
  
  <pre><code>&lt;Button x:Name="btnOK" VerticalAlignment="Center" Content="OK" IsDefault="True"  Margin="0" Click="btnOK_Click"&gt;
                      &lt;Button.Style&gt;
                        &lt;Style BasedOn="{StaticResource DefaultButton}"&gt;
                              &lt;Style.Triggers&gt;
                                  &lt;DataTrigger Binding="{Binding ElementName=ddlWageTypes, Path=SelectedItem}" Value="{x:Null}"&gt;
                                      &lt;Setter Property="Button.IsEnabled" Value="false"/&gt;
                                  &lt;/DataTrigger&gt;
                                  &lt;DataTrigger Binding="{Binding ElementName=ddlJobTitles, Path=SelectedItem}" Value="{x:Null}"&gt;
                                      &lt;Setter Property="Button.IsEnabled" Value="false"/&gt;
                                  &lt;/DataTrigger&gt;
                              &lt;/Style.Triggers&gt;
                          &lt;/Style&gt;
                      &lt;/Button.Style&gt;
                  &lt;/Button&gt;
  </code></pre>
  
  <p>I've tried adding BasedOn="{StaticResouce MyDefaultButtonStyleName}" to the style tag but it blows up at runtime.  </p>
  
  <p>The error is "'System.Windows.Style' value cannot be assigned to property 'Style' of object 'System.Windows.Controls.Button'. Can only base on a Style with target type that is base type 'IFrameworkInputElement'.  Error at object 'System.Windows.Style' in markup file"</p>
  
  <p>Is there a was to do this in XAML without overwriting default style.</p>
  
  <p>EDIT: Code Sample Updated.
  I get an error on OKButtonStyle saying "Cannot add element to property 'Resources', because the property can have only one child element if it uses an explicit collection tag.  Error at object 'System.Windows.Style' in markup file "</p>
  
  <pre><code>&lt;UserControl x:Class="UK.Budgeting.XBAP.ShiftDiff.NewFTEPremiumPaySummary"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:compModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
      xmlns:local="clr-namespace:UK.Budgeting.XBAP.ShiftDiff"&gt;
      &lt;UserControl.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary Source="CellTemplates.xaml"/&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
  
        &lt;Style TargetType="{x:Type Button}" x:Key="OKButtonStyle" BasedOn="{StaticResource DefaultButton}"&gt;
          &lt;Style.Triggers&gt;
            &lt;DataTrigger Binding="{Binding ElementName=ddlWageTypes, Path=SelectedItem}" Value="{x:Null}"&gt;
              &lt;Setter Property="Button.IsEnabled" Value="false"/&gt;
            &lt;/DataTrigger&gt;
            &lt;DataTrigger Binding="{Binding ElementName=ddlJobTitles, Path=SelectedItem}" Value="{x:Null}"&gt;
              &lt;Setter Property="Button.IsEnabled" Value="false"/&gt;
            &lt;/DataTrigger&gt;
          &lt;/Style.Triggers&gt;
        &lt;/Style&gt;
  
      &lt;/UserControl.Resources&gt;
      &lt;Grid&gt;
          &lt;Rectangle Style="{StaticResource DialogRectangle}"/&gt;
          &lt;Border Style="{StaticResource DialogBorder}"&gt;
              &lt;Grid HorizontalAlignment="Center" VerticalAlignment="Center" Background="White"&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition/&gt;
                      &lt;ColumnDefinition Width="5"/&gt;
                      &lt;ColumnDefinition MinWidth="300"/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition/&gt;
                      &lt;RowDefinition Height="2"/&gt;
                      &lt;RowDefinition/&gt;
                      &lt;RowDefinition Height="2"/&gt;
                      &lt;RowDefinition/&gt;
                      &lt;RowDefinition Height="2"/&gt;
                      &lt;RowDefinition/&gt;
                  &lt;/Grid.RowDefinitions&gt;
  
                  &lt;TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource LabelStyle}"&gt;Wage Type&lt;/TextBlock&gt;
                  &lt;TextBlock Grid.Column="0" Grid.Row="2" Style="{StaticResource LabelStyle}"&gt;Job Title&lt;/TextBlock&gt;
  
                  &lt;ComboBox x:Name="ddlWageTypes" VerticalAlignment="Top" Grid.Column="2" Grid.Row="0"
                            DisplayMemberPath="DisplayName"
                            SelectedValuePath="WageTypeCode"/&gt;
                  &lt;ComboBox x:Name="ddlJobTitles" VerticalAlignment="Top" Grid.Column="2" Grid.Row="2"
                            DisplayMemberPath="JobTitle"
                            SelectedValuePath="JobCode"/&gt;
  
                  &lt;StackPanel Grid.Column="2" Grid.Row="6" VerticalAlignment="Top" Orientation="Horizontal" Margin="5"&gt;
                    &lt;Button x:Name="btnOK" VerticalAlignment="Center" Content="OK" IsDefault="True"  Margin="0" Click="btnOK_Click" Style="{StaticResource OKButtonStyle}"/&gt;
                      &lt;Button x:Name="btnCancel" VerticalAlignment="Center" Content="Cancel" IsCancel="True" Margin="10,0,0,0" Click="btnCancel_Click"/&gt;
                  &lt;/StackPanel&gt;
              &lt;/Grid&gt;
          &lt;/Border&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>