BUG ? Commands not working properly

Oct 2, 2008 at 11:09 AM
Hi

I have a datagrid containing my business objects and a toolbar with a save button, but I have problems using commands.
Let me first give you my "environment"

My Command:
    <CommandBinding Command="ApplicationCommands.Save"
                      Executed="OnSave"
                      CanExecute="CanSave" />
My Button:
        <Button Command="ApplicationCommands.Save">
          <StackPanel>
            <TextBlock Text="{StaticResource C.Save}"/>
            <Image Source="{x:Null}"/>
          </StackPanel>
        </Button>

My Grid columns (just the first two):
          <toolkit:DataGridCheckBoxColumn Header="{StaticResource P.RowSelectedYN}" DataFieldBinding="{Binding Path=IsSelected}" />
          <toolkit:DataGridTextColumn Header="{StaticResource P.ModuleName}" DataFieldBinding="{Binding Path=ModuleName, ValidatesOnDataErrors=True}" ElementStyle="{StaticResource styTextBoxColumnStyleGif}"/>

My Code for CanSave and OnSave:
   Private Sub CanSave(ByVal sender As System.Object, ByVal e As CanExecuteRoutedEventArgs)
      e.CanExecute = True
   End Sub
   Private Sub OnSave(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
      Call moAction.SaveList(mltModule)
   End Sub

Now to the problem I run into:
1) When I press the button before doing any changes to the grid, OnSave is called, the button remains active.
2) When I press the button after doing changes in a DataGridTextColumn, OnSave is not called, the button is disabled. The button is enabled again when I click in any cell of the grid (including again in the changed cell). Any further change to a DataGridTextColumn in any other row (or even the same first row) leads to the same result (OnSaev not called, button disabled)
3) When I change the DataGridCheckBoxColumncolumn (click the checkbox), and press the button, OnSave is called, the button remains active. After changing a DataGridTextColumn's text, there is the same behaviour as described in 2)

In General: any change to a DataGridTextColumn leads to not running OnSave, any change to a DataGridCheckBoxColumncolumn leads to OnSave being called.

To be sure that not "ApplicationCommand.Save" has some strange internal behaviour, I created a custom routed  command like so
Public NotInheritable Class Commands
   Private Sub New()
   End Sub
   Public Shared ReadOnly Foo As New RoutedCommand()
End Class

With the following binding definition:
    <CommandBinding
      Command="{x:Static local:Commands.Foo}"
      CanExecute="Foo_CanExecute"
      Executed="Foo_Executed"
      />

And the following Button:
        <Button Command="{x:Static local:Commands.Foo}">
          <StackPanel>
            <TextBlock Text="{StaticResource C.Save}"/>
            <Image Source="{x:Null}"/>
          </StackPanel>
        </Button>

This had exactly the same result

Hope you can fix this
Regards
Klaus
Oct 7, 2008 at 8:37 PM
Hi

am I the only one who has this problem?
Or is there a way out?

Regards
Klaus
Oct 8, 2008 at 10:04 PM
Hi

found the problem: setting         FocusManager.IsFocusScope="False" for the toolbar does the trick

Best regards
Klaus