Home Forums WPF controls Xceed DataGrid for WPF Commands: CanExecute doesn´t fire when interacting with Grid

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25779 |

    Hi!

    My first post here, so “hello everybody” !

    My problem:
    Let´s sav I have a UserControl with the Datagrid as one of many controls on it. That UserControl has some CommandBindings and listens to the CanExecute Events of the CommandBindings.

    Unfortunately the CanExecute event does not fire when interacting with the grid. Let´s say the selected Row changed: No CanExecute Event.
    If I click a TextBox on the UserControl: CanExecute Event fires.
    The focus gets back to the grid: It does not fire 🙁

    Can anybody help me? I really need to control my commands according to the selected rows in the grid!

    Pleas ask if anything is unclear due to my english!

    Regrads
    Christian

    Imported from legacy forums. Posted by Christian (had 3378 views)

    User (Old forums)
    Member
    Post count: 23064

    I confirmed this problem as well. It’s a real nagging issue but I can’t reproduce it in a small case. It would be nice if you can create a repro case.

    Imported from legacy forums. Posted by nat (had 444 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

    I just tried to create a very simple Repro case but it worked there… But I will go one trying…

    Imported from legacy forums. Posted by Christian (had 346 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok. Here is one:

    We have a MasterWindow with a Toolbar. That toolbar has a Button that triggers the Save Command. And there is a TextBox on the MainWindow.

    <StackPanel Background=”Gray”>
    <ToolBarTray Name=”Toolbar”>
    <ToolBar Band=”1″ BandIndex=”1″>
    <Button Command=”ApplicationCommands.Save” Content=”Command”/>
    </ToolBar>
    </ToolBarTray>
    <TextBox Text=”UserControl loses Focus if you click me. The Command gets disabled”/>
    <uc:UserControl1/>
    </StackPanel>

    As you see there is a UserControl too. That UserControl has a CommandBinding for the SaveCommand. And a TextBox and the GridControl.

    — xaml: —
    <UserControl.CommandBindings>
    <CommandBinding Command=”ApplicationCommands.Save” CanExecute=”CommandBinding_CanExecute”/>
    </UserControl.CommandBindings>

    <Grid>
    <Grid.RowDefinitions>
    <RowDefinition Height=”Auto”/>
    <RowDefinition Height=”*”/>
    </Grid.RowDefinitions>
    <TextBox Text=”My Focus triggers CanExecute” Margin=”10″/>
    <xcdg:DataGridControl Name=”Grid” Grid.Row=”1″ Margin=”10″ />
    </Grid>

    — cs: —

    public UserControl1()
    {
    InitializeComponent();
    Grid.ItemsSource = “My does not”;
    }

    private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
    {
    e.CanExecute = true;
    }

    if you run this you´ll see my Problem:
    If you click the textbox on the mainwindow the command gets disabled, because the UserControl does not own the focus. That seems reasonable and is what I expected.
    If you click the textbox in the UserControl the Command gets enabled. Great.
    But if you click the Grid instead nothing happens…

    Regards
    Christian

    Imported from legacy forums. Posted by Christian (had 686 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

    I found a solution.

    When i set FocusManager.IsFocusScope=”False” on the grid it works…

    Imported from legacy forums. Posted by Christian (had 4570 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.