
Thanks,
-Craig
P.S. - I noticed that when I set a bp in my debugger and examine the SyntaxEditor, its ContextMenu property is null.
[Modified at 03/04/2011 11:55 AM]
I've been setting a custom ContextMenu via the SyntaxEditor's ContextMenu property for a long while now and overall, it works great. However, I've discovered an issue that I need help with.
If the SyntaxEditor's Document becomes readonly and then later becomes writeable, all the ContextMenu commands remain disabled.
To repro this, you can use the below sample and the following steps:
You'll see that the context menu items are all disabled, despite some being enabled before step 2.
Question: Is there something I can change so that the context menus re-enable themselves appropriately?
Thanks,
-Craig
Sample code:
MainWindow.xaml:
<Window
x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:SyntaxEditor="http://schemas.actiprosoftware.com/winfx/xaml/syntaxeditor"
Title="MainWindow"
Height="350"
Width="525"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<CheckBox
x:Name="readonlyToggle"
Content="Toggle Read-Only"
Grid.Row="0"
Click="ReadonlyToggle_OnClick"
/>
<SyntaxEditor:SyntaxEditor
x:Name="syntaxEditor"
Grid.Row="1"
IsDefaultContextMenuEnabled="False"
>
<SyntaxEditor:SyntaxEditor.ContextMenu>
<ContextMenu>
<MenuItem
Header="Undo"
Command="SyntaxEditor:EditorCommands.Undo"
InputGestureText="Ctrl+Z"
/>
<MenuItem
Header="Redo"
Command="SyntaxEditor:EditorCommands.Redo"
InputGestureText="Ctrl+Y"
/>
<Separator
/>
<MenuItem
Header="Cu_t"
Command="SyntaxEditor:EditorCommands.CutToClipboard"
InputGestureText="Ctrl+X"
/>
<MenuItem
Header="_Copy"
Command="SyntaxEditor:EditorCommands.CopyToClipboard"
InputGestureText="Ctrl+C"
/>
<MenuItem
Header="_Paste"
Command="SyntaxEditor:EditorCommands.PasteFromClipboard"
InputGestureText="Ctrl+V"
/>
<MenuItem
Header="_Delete"
Command="SyntaxEditor:EditorCommands.Delete"
/>
<Separator
/>
<MenuItem
Header="Select _All"
Command="SyntaxEditor:EditorCommands.SelectAll"
InputGestureText="Ctrl+A"
/>
</ContextMenu>
</SyntaxEditor:SyntaxEditor.ContextMenu>
</SyntaxEditor:SyntaxEditor>
</Grid>
</Window>
MainWindow.xaml.cs:
namespace WpfApplication4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ReadonlyToggle_OnClick(object sender, RoutedEventArgs e)
{
syntaxEditor.Document.IsReadOnly = readonlyToggle.IsChecked.GetValueOrDefault();
}
}
}
Hi Craig,
Are you running the latest version? Perhaps you don't have focus in the editor when the right-click is done? Menu item commands operate on whatever has focus. I believe in recent builds though we added something to focus on right-click.
I'm testing this with WPF Studio 12.2.570.
Some questions:
In the meantime, I'll try authoring a behavior to focus the SyntaxEditor when a right click occurs.
-Craig
Yes I did test with your code and just looked up the build 571 release notes. It looks like we added focus on right-click in that build. So that's why it worked for me.
That's great, thanks. Also, I've confirmed that if I use
private void SyntaxEditor_OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
syntaxEditor.ActiveView.Focus();
}
with earlier builds, the ContextMenu works.
Thanks again,
-Craig
Please log in to a validated account to post comments.