Skip to content

Context menu ApplicationCommands.Cut still enabled when IsReadOnly = true #444

@CodingOctocat

Description

@CodingOctocat

Description

When a TextEditor is set to IsReadOnly = true, context menu items (or any UI elements) bound to standard ApplicationCommands.Cut remain enabled, even though those operations have no effect.
This behavior is inconsistent with the expected WPF command pattern, where CanExecute should return false when the editor is read-only.

If add CommandTarget, it always not work.
CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"

Image

Example Code

<avalonedit:TextEditor x:Name="editor" IsReadOnly="True">
    <avalonedit:TextEditor.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Cut" Command="ApplicationCommands.Cut" /> ❌ always enabled

            <MenuItem Command="{x:Static ApplicationCommands.Cut}"
                      IsEnabled="{Binding PlacementTarget.IsReadOnly,
                                 RelativeSource={RelativeSource AncestorType=ContextMenu},
                                 Converter={StaticResource Boolean2BooleanReConverter}}" /> ✅

            <MenuItem Header="Copy" Command="ApplicationCommands.Copy" /> ✅

            <MenuItem Command="{x:Static ApplicationCommands.Copy}"
                      CommandTarget="{Binding PlacementTarget,
                        RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" /> ❌ always disabled

            <MenuItem Header="Paste" Command="ApplicationCommands.Paste" /> ✅
        </ContextMenu>
    </avalonedit:TextEditor.ContextMenu>
</avalonedit:TextEditor>

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