Message 1 of 1
Adding CanExecute to RelayCommand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
First of all I would like to say a big thanks to @nice3point for the wonderfull template / samples etc
I am just looking at the "SingleProjectWpfModelessApplication" sample to better understand MVVM.
within the ViewModel, for the RelayCommand, I am trying learn how to implement CanExecute.
Lets say for the Delete button
[RelayCommand]
private async Task DeleteElementAsync()
{
var deletedId = await _asyncIdExternalHandler.RaiseAsync(application =>
{
var document = application.ActiveUIDocument.Document;
var selectionConfiguration = new SelectionConfiguration();
var reference = application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, selectionConfiguration.Filter);
var transaction = new Transaction(document);
transaction.Start("Delete element");
document.Delete(reference.ElementId);
transaction.Commit();
return reference.ElementId;
});
TaskDialog.Show("Deleted element", $"ID: {deletedId}");
}
lets say I want to check if someting is selected then this button can execute.
I can change the RelayCommand to
[RelayCommand(CanExecute = nameof(IsSelectionNotNull))]
then I can create the method
private bool IsSelectionNotNull()
{ if (reference is null)
{return false;}
else
{return true;}
}
What I am struggling with is where to create this method while within same scope