Wpf xaml button with AccessText doesn't seem to request CanExecute

Explanation

  • Purpose: In my working wpf application, I want to add AccessTextto a button that is bound to a command with a predicate that evaluates whether a window / control is busy and thus disables the button.
  • Status: The button command works fine and is properly enabled until added AccessText. (I use MvvmLight to support my ICommand.)
  • Problem: After adding, the AccessTextcommand is still linked, but CanExecuteit seems to be no longer requested, and the button is always on. (My ideal solution would not have been without XAML code.)

Example

XAML:

AT:

<Button Command="{Binding NavToStoresSearchCmd}" Content="Stores" Height="30"/>

Does not work:

<Button Command="{Binding NavToStoresSearchCmd}" Height="30">
    <AccessText>S_tores</AccessText>
</Button>

C # (ViewModel):

public ICommand NavToStoresSearchCmd { get => new RelayCommand(OnNavToStoresSearch, () => IsNotBusy); }

( IsNotBusy OnNavToStoresSearch , CanExecute UNTIL. AccessText.)

+4
1

, . :

XAML:

<Button Command="{Binding BrowseCommand}">
    <AccessText>_Browse</AccessText>
</Button>

# (ViewModel):

:

BrowseCommand = new RelayCommand( BrowseCommandHandler, () => CanBrowse );

CanBrowse:

private bool _canBrowse;
public bool CanBrowse
{
    get { return _canBrowse; }
    set { _canBrowse = value; BrowseCommand.RaiseCanExecuteChanged(); }
}

, "RaiseCanExecuteChanged()" RelayCommand?

(Edit: , submit. , !)

, RaiseCanExecuteChanged. WPF CommandManager CanExecute, , , .. . , , CommandManager , ( ) RaiseCanExecuteChanged, , .

( ) , , , "RaiseCanExecuteChanged", . ...

using GalaSoft.MvvmLight.Command;

using GalaSoft.MvvmLight.CommandWpf;

"RaiseCanExecuteChanged()" , , . , ...

+2

Source: https://habr.com/ru/post/1691926/


All Articles