title: CanExecute command carries out update instead of Execute command
body: <p>I have created methods in C# visual studio 2010 that disable or enable buttons in a record using wpf commands as below:</p>
  
  <pre><code>     private void CanSavePageCommandExecute(object sender, CanExecuteRoutedEventArgs e)
      {
          **if (studentsViewSource != null &amp;&amp; studentsViewSource.View != null &amp;&amp; novelDataSetTableAdapter.Update(novelDataSet.students) &gt; 0)
          {
              e.CanExecute = true;
              //e.Handled = true;
          }
          else
          {
              e.CanExecute = false;
          }
      }**
  </code></pre>
  
  <p>should be:</p>
  
  <pre><code>  private void CanSavePageCommandExecute(object sender, CanExecuteRoutedEventArgs e)
      {
  
         e.CanExecute = studentsViewSource != null &amp;&amp; this.novelDataSet.HasChanges();
         e.Handled = true;
  
      }
  
       private void OnSavePageCommandExecute(object sender, ExecutedRoutedEventArgs e)
      {
          if (novelDataSetTableAdapter.Update(novelDataSet.students) &gt; 0)
  
              MessageBox.Show("Entries have been updated !", "DATA STATUS");
          else
              MessageBox.Show("Error occurred!", "DATA NOT SAVED");
      }
  </code></pre>
  
  <p>The 'CanSavePageCommandExecute' is supposed to just disable the SAVE button if the enclosed conditions are met. It actually does that but it goes a step further and saves the data to the database.
  The 'OnSavePageCommandExecute' command is not carried out even if I just test using MessageBox.show.
  How do I prevent the CanExecute command from saving data to just enabling and disabling button based on changes made to the datasets?</p>
  
  <p>I am not using MVVM but this is part of the Xaml code from a user control:</p>
  
  <pre><code>  &lt;UserControl.CommandBindings&gt;
      &lt;CommandBinding Command="New" 
              CanExecute="CanNewPageCommandExecute" Executed="OnNewPageCommandExecute" /&gt;
      &lt;CommandBinding Command="NavigationCommands.PreviousPage" 
              CanExecute="CanPreviousPageCommandExecute" Executed="OnPreviousPageCommandExecute" /&gt;
      &lt;CommandBinding Command="NavigationCommands.NextPage"
              CanExecute="CanNextPageCommandExecute" Executed="OnNextPageCommandExecute" /&gt;
      &lt;CommandBinding Command="FirstPage"
              CanExecute="CanPreviousPageCommandExecute" Executed="OnFirstPageCommandExecute" /&gt;
      &lt;CommandBinding Command="LastPage"
              CanExecute="CanNextPageCommandExecute" Executed="OnLastPageCommandExecute" /&gt;
      &lt;CommandBinding Command="{x:Static local:student.saves}"
              CanExecute="CanSavePageCommandExecute" Executed="OnSavePageCommandExecute" /&gt;
      &lt;CommandBinding Command="Delete"
              CanExecute="CanDeletePageCommandExecute" Executed="OnDeletePageCommandExecute" /&gt;
  &lt;/UserControl.CommandBindings&gt;
  
  &lt;Border Width="Auto" Height="Auto" BorderThickness="1" CornerRadius="2"&gt;
      &lt;dxlc:LayoutControl Name="layoutControl1" Cursor="Arrow"&gt;
          &lt;dxlc:LayoutGroup Orientation="Vertical" Height="303"&gt;
              &lt;Border BorderThickness="1" Height="160" Width="160" BorderBrush="Black" Margin="0,0,0,20"&gt;
                  &lt;Border.Background&gt;
                      &lt;ImageBrush ImageSource="/college12;component/images/prime.jpg" Stretch="Uniform" TileMode="None" /&gt;
                  &lt;/Border.Background&gt;
                  &lt;Image Height="150" Name="studypixx" Stretch="UniformToFill" Width="150" UseLayoutRounding="False" DataContext="{StaticResource studentsViewSource}" Source="{Binding Path=studyphoto, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /&gt;
              &lt;/Border&gt;
              &lt;Button Content="Upload Photo" Height="23" HorizontalAlignment="Center" Name="studentphotoupload" VerticalAlignment="Top" Width="116" ToolTip="Inserts photo" Background="#FFEC3B3B" BorderBrush="Black" Cursor="Hand" Click="studentphotoupload_Click" /&gt;
              &lt;TextBox Name="photo_text" Width="160" HorizontalAlignment="Left" Height="20" IsHitTestVisible="False" Visibility="Visible" Text="{Binding Path=studyphoto, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" DataContext="{StaticResource studentsViewSource}" /&gt;
              &lt;dxlc:LayoutGroup Name="layoutGroup3" View="GroupBox" Width="160" Height="62"&gt;
                  &lt;Button Content="NEW STUDENT" Height="23" HorizontalAlignment="Center" Name="addstudent" VerticalAlignment="Bottom" Width="93" Command="ApplicationCommands.New" Cursor="Hand" /&gt;
              &lt;/dxlc:LayoutGroup&gt;
          &lt;/dxlc:LayoutGroup&gt;
          &lt;dxlc:LayoutGroup Orientation="Vertical"&gt;
              &lt;dxlc:LayoutGroup Name="layoutGroup1" View="GroupBox" Height="238" UseLayoutRounding="True" Orientation="Vertical" Width="450" DragScrolling="False" Header="{Binding Path=surname}" DataContext="{StaticResource studentsViewSource}"&gt;
                  &lt;dxlc:LayoutGroup&gt;
                      &lt;dxlc:LayoutItem Label="First Name" Name="layoutItem1"&gt;
                          &lt;dxe:TextEdit Name="first_name" FontFamily="Consolas" UseLayoutRounding="False" CharacterCasing="Upper" MaskSaveLiteral="True" Mask="[a-zA-Z]+" MaskType="RegEx" EditValue="{Binding Path=firstname, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=LostFocus}" /&gt;
                      &lt;/dxlc:LayoutItem&gt;
                      &lt;dxlc:LayoutItem Label="Middle Name" Name="layoutItem2"&gt;
                          &lt;dxe:TextEdit Name="other_name" FontFamily="Consolas" UseLayoutRounding="False" CharacterCasing="Upper" MaskSaveLiteral="True" Mask="[a-zA-Z]+" MaskType="RegEx" EditValue="{Binding Path=othername, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                  &lt;/dxlc:LayoutGroup&gt;
                  &lt;dxlc:LayoutGroup&gt;
                      &lt;dxlc:LayoutItem Label="Surname" Name="layoutItem3"&gt;
                          &lt;dxe:TextEdit Name="other_surname" FontFamily="Consolas" UseLayoutRounding="False" CharacterCasing="Upper" MaskSaveLiteral="True" Mask="[a-zA-Z]+" MaskType="RegEx" EditValue="{Binding Path=surname, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=LostFocus}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                      &lt;dxlc:LayoutItem Label="Email" Name="layoutItem10"&gt;
                          &lt;dxe:TextEdit Name="email_address" EditValue="{Binding Path=email, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                  &lt;/dxlc:LayoutGroup&gt;
                  &lt;dxlc:LayoutGroup&gt;
                      &lt;dxlc:LayoutItem Label="Birth Date" Name="layoutItem4"&gt;
                          &lt;dxe:DateEdit Name="birth_date" Mask="d/MM/yyyy" MaskSaveLiteral="False" MaskType="DateTime" MaskUseAsDisplayFormat="True" UseLayoutRounding="False" FontFamily="Consolas" FontSize="12" EditValue="{Binding Path=birthdate, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                      &lt;dxlc:LayoutItem Label="Enrol Date" Name="layoutItem5"&gt;
                          &lt;dxe:DateEdit Name="enrol_date" MaskUseAsDisplayFormat="True" MaskType="DateTime" MaskSaveLiteral="False" Mask="d/MM/yyyy" UseLayoutRounding="False" FontFamily="Consolas" FontSize="12" EditValue="{Binding Path=enroldate, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                  &lt;/dxlc:LayoutGroup&gt;
                  &lt;dxlc:LayoutGroup&gt;
                      &lt;dxlc:LayoutItem Label="Enrol NO." Name="layoutItem6"&gt;
                          &lt;dxe:TextEdit Name="enrol_no" FontFamily="Consolas" FontSize="10" EditValue="{Binding Path=enrolnum, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                      &lt;dxlc:LayoutItem Label="Phone NO." Name="layoutItem9"&gt;
                          &lt;dxe:TextEdit Name="phone_no" Mask="(\d?\d?\d?\d)\d\d-\d\d-\d\d" MaskType="Regular" MaskUseAsDisplayFormat="True" FontFamily="Consolas" FontSize="10" MaskBeepOnError="False" MaskSaveLiteral="False" AcceptsReturn="True" AcceptsTab="True" EditValue="{Binding Path=phone, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                  &lt;/dxlc:LayoutGroup&gt;
                  &lt;dxlc:LayoutGroup&gt;
                      &lt;dxlc:LayoutItem Label="Address" Name="layoutItem7"&gt;
                          &lt;dxe:TextEdit Name="address" FontFamily="Consolas" UseLayoutRounding="False" CharacterCasing="Upper" EditValue="{Binding Path=address, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                      &lt;dxlc:LayoutItem Label="Town/City" Name="layoutItem8"&gt;
                          &lt;dxe:TextEdit Name="town_city" FontFamily="Consolas" UseLayoutRounding="False" CharacterCasing="Upper" Mask="[a-zA-Z]+" MaskType="RegEx" EditValue="{Binding Path=town, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, UpdateSourceTrigger=PropertyChanged}"/&gt;
                      &lt;/dxlc:LayoutItem&gt;
                  &lt;/dxlc:LayoutGroup&gt;
              &lt;/dxlc:LayoutGroup&gt;
              &lt;dxlc:LayoutGroup Name="layoutGroup2" View="GroupBox" Width="450"&gt;
                  &lt;Button Content="FIRST" Height="23" HorizontalAlignment="Left" Name="firststudent" VerticalAlignment="Top" Width="75" Cursor="Hand" Command="NavigationCommands.FirstPage" /&gt;
                  &lt;Button Content="PREVIOUS" Height="23" HorizontalAlignment="Left" Name="previoustudent" VerticalAlignment="Top" Width="75" Command="NavigationCommands.PreviousPage" ToolTip="Preceding student record" Cursor="Hand" /&gt;
                  &lt;Button Content="NEXT" Height="23" HorizontalAlignment="Left" Name="nextstudent" VerticalAlignment="Top" Width="75" Command="NavigationCommands.NextPage" ToolTip="Next student record" Cursor="Hand" /&gt;
                  &lt;Button Content="LAST" Height="23" HorizontalAlignment="Left" Name="laststudent" VerticalAlignment="Top" Width="75" Cursor="Hand" Command="NavigationCommands.LastPage" /&gt;
                  &lt;Button Content="SAVE" Height="23" HorizontalAlignment="Left" Name="savestudent" VerticalAlignment="Top" Width="75" Cursor="Hand" Command="{x:Static local:student.saves}"/&gt;
              &lt;/dxlc:LayoutGroup&gt;
          &lt;/dxlc:LayoutGroup&gt;
      &lt;/dxlc:LayoutControl&gt;
  &lt;/Border&gt;
  </code></pre>