Skip to content

Implementing ICommand? #232

@ktraunmueller

Description

@ktraunmueller

I would like to assign a command to a MenuFlyoutItem to enable or disable it at runtime (i.e., when the owning MenuBarItem is about to open):

let formatBoldItem = MenuFlyoutItem()
formatBoldItem.command = FormatBoldCommand()

where FormatBoldCommand would be something like

import WinUI
import WindowsFoundation

final class FormatBoldCommand: ICommand {

    func canExecute(_ parameter: Any!) throws -> Bool {
        return ...
    }

    func execute(_ parameter: Any!) throws {
        
    }

    lazy var canExecuteChanged: Event<EventHandler<Any?>> = ...
}

I see ICommand is implemented for example in

public enum __IMPL_Microsoft_UI_Xaml_Input {
   ...

    fileprivate class ICommandImpl: ICommand, WinRTAbiImpl {

and was wondering if that's something that's also possible in user code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions