Skip to content

Commit efce863

Browse files
authored
Merge pull request #354 from GID0317/Gallery-Enchantment-CodePresenter-ContextMenu-Behaviour
Gallery Revamp: Match CodePresenter Context Menu visibility to match WinUI3 and iUWM Behavior
1 parent 209e040 commit efce863

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

source/iNKORE.UI.WPF.Modern.Gallery/Controls/SampleCodePresenter.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ private void SampleCodePresenter_Loaded(object sender, RoutedEventArgs e)
141141
SampleHeader.Text = IsCSharpSample ? "C#" : "XAML";
142142

143143
FixAvalonEditScrolling();
144+
145+
try
146+
{
147+
if (CodePresenter?.ContextMenu != null)
148+
{
149+
//show Copy only when there is a selection; always show Select All.
150+
CodePresenter.ContextMenu.Opened += (s, args) =>
151+
{
152+
var hasSelection = CodePresenter?.SelectionLength > 0;
153+
foreach (var mi in CodePresenter.ContextMenu.Items.OfType<MenuItem>())
154+
{
155+
if (mi.Command == ApplicationCommands.Copy)
156+
{
157+
mi.Visibility = hasSelection == true ? Visibility.Visible : Visibility.Collapsed;
158+
}
159+
else if (mi.Command == ApplicationCommands.SelectAll)
160+
{
161+
mi.Visibility = Visibility.Visible;
162+
}
163+
}
164+
};
165+
}
166+
}
167+
catch
168+
{
169+
// Swallow any errors here to avoid breaking the sample if localization isn't available.
170+
}
144171
}
145172

146173
private void CodePresenter_Loaded(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)