-
Notifications
You must be signed in to change notification settings - Fork 491
Open
Description
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}}}"
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
Labels
No labels