Skip to content

Commit 1377831

Browse files
committed
Merge branch 'develop' into main
2 parents 1f8ca06 + b683392 commit 1377831

File tree

7 files changed

+61
-43
lines changed

7 files changed

+61
-43
lines changed

src/MahApps.Metro/Controls/ColorPicker/BuildInColorPalettes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public static void AddColorToRecentColors(Color? color, IEnumerable recentColors
5151
if (recentColors is ObservableCollection<Color?> collection)
5252
{
5353
var oldIndex = collection.IndexOf(color);
54-
if (oldIndex > -1)
54+
if (oldIndex > 0)
5555
{
5656
collection.Move(oldIndex, 0);
5757
}
58-
else
58+
else if (oldIndex < 0)
5959
{
6060
if (collection.Count >= maxCount)
6161
{

src/MahApps.Metro/Controls/Dialogs/InputDialog.xaml.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using System.Windows;
89
using System.Windows.Input;
@@ -11,6 +12,8 @@ namespace MahApps.Metro.Controls.Dialogs
1112
{
1213
public partial class InputDialog : BaseMetroDialog
1314
{
15+
private CancellationTokenRegistration cancellationTokenRegistration;
16+
1417
/// <summary>Identifies the <see cref="Message"/> dependency property.</summary>
1518
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(nameof(Message), typeof(string), typeof(InputDialog), new PropertyMetadata(default(string)));
1619

@@ -81,15 +84,7 @@ internal Task<string> WaitForButtonPressAsync()
8184

8285
KeyEventHandler escapeKeyHandler = null;
8386

84-
Action cleanUpHandlers = null;
85-
86-
var cancellationTokenRegistration = this.DialogSettings.CancellationToken.Register(() =>
87-
{
88-
cleanUpHandlers();
89-
tcs.TrySetResult(null);
90-
});
91-
92-
cleanUpHandlers = () =>
87+
Action cleanUpHandlers = () =>
9388
{
9489
this.PART_TextBox.KeyDown -= affirmativeKeyHandler;
9590

@@ -101,9 +96,20 @@ internal Task<string> WaitForButtonPressAsync()
10196
this.PART_NegativeButton.KeyDown -= negativeKeyHandler;
10297
this.PART_AffirmativeButton.KeyDown -= affirmativeKeyHandler;
10398

104-
cancellationTokenRegistration.Dispose();
99+
this.cancellationTokenRegistration.Dispose();
105100
};
106101

102+
this.cancellationTokenRegistration = this.DialogSettings
103+
.CancellationToken
104+
.Register(() =>
105+
{
106+
this.BeginInvoke(() =>
107+
{
108+
cleanUpHandlers();
109+
tcs.TrySetResult(null);
110+
});
111+
});
112+
107113
escapeKeyHandler = (sender, e) =>
108114
{
109115
if (e.Key == Key.Escape || (e.Key == Key.System && e.SystemKey == Key.F4))

src/MahApps.Metro/Controls/Dialogs/LoginDialog.xaml.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using System.Windows;
89
using System.Windows.Controls;
@@ -13,6 +14,8 @@ namespace MahApps.Metro.Controls.Dialogs
1314
{
1415
public partial class LoginDialog : BaseMetroDialog
1516
{
17+
private CancellationTokenRegistration cancellationTokenRegistration;
18+
1619
/// <summary>Identifies the <see cref="Message"/> dependency property.</summary>
1720
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(nameof(Message), typeof(string), typeof(LoginDialog), new PropertyMetadata(default(string)));
1821

@@ -181,15 +184,7 @@ internal Task<LoginDialogData> WaitForButtonPressAsync()
181184

182185
KeyEventHandler escapeKeyHandler = null;
183186

184-
Action cleanUpHandlers = null;
185-
186-
var cancellationTokenRegistration = this.DialogSettings.CancellationToken.Register(() =>
187-
{
188-
cleanUpHandlers();
189-
tcs.TrySetResult(null);
190-
});
191-
192-
cleanUpHandlers = () =>
187+
Action cleanUpHandlers = () =>
193188
{
194189
this.PART_TextBox.KeyDown -= affirmativeKeyHandler;
195190
this.PART_TextBox2.KeyDown -= affirmativeKeyHandler;
@@ -202,9 +197,20 @@ internal Task<LoginDialogData> WaitForButtonPressAsync()
202197
this.PART_NegativeButton.KeyDown -= negativeKeyHandler;
203198
this.PART_AffirmativeButton.KeyDown -= affirmativeKeyHandler;
204199

205-
cancellationTokenRegistration.Dispose();
200+
this.cancellationTokenRegistration.Dispose();
206201
};
207202

203+
this.cancellationTokenRegistration = this.DialogSettings
204+
.CancellationToken
205+
.Register(() =>
206+
{
207+
this.BeginInvoke(() =>
208+
{
209+
cleanUpHandlers();
210+
tcs.TrySetResult(null);
211+
});
212+
});
213+
208214
escapeKeyHandler = (sender, e) =>
209215
{
210216
if (e.Key == Key.Escape || (e.Key == Key.System && e.SystemKey == Key.F4))

src/MahApps.Metro/Controls/Dialogs/MessageDialog.xaml.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using System.Windows;
89
using System.Windows.Input;
@@ -17,6 +18,7 @@ public partial class MessageDialog : BaseMetroDialog
1718
{
1819
private const string ACCENT_BUTTON_STYLE = "MahApps.Styles.Button.Dialogs.Accent";
1920
private const string ACCENT_HIGHLIGHT_BUTTON_STYLE = "MahApps.Styles.Button.Dialogs.AccentHighlight";
21+
private CancellationTokenRegistration cancellationTokenRegistration;
2022

2123
/// <summary>Identifies the <see cref="Message"/> dependency property.</summary>
2224
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(nameof(Message), typeof(string), typeof(MessageDialog), new PropertyMetadata(default(string)));
@@ -136,7 +138,7 @@ internal Task<MessageDialogResult> WaitForButtonPressAsync()
136138
}
137139
}));
138140

139-
TaskCompletionSource<MessageDialogResult> tcs = new TaskCompletionSource<MessageDialogResult>();
141+
var tcs = new TaskCompletionSource<MessageDialogResult>();
140142

141143
RoutedEventHandler negativeHandler = null;
142144
KeyEventHandler negativeKeyHandler = null;
@@ -152,15 +154,7 @@ internal Task<MessageDialogResult> WaitForButtonPressAsync()
152154

153155
KeyEventHandler escapeKeyHandler = null;
154156

155-
Action cleanUpHandlers = null;
156-
157-
var cancellationTokenRegistration = this.DialogSettings.CancellationToken.Register(() =>
158-
{
159-
cleanUpHandlers?.Invoke();
160-
tcs.TrySetResult(this.ButtonStyle == MessageDialogStyle.Affirmative ? MessageDialogResult.Affirmative : MessageDialogResult.Negative);
161-
});
162-
163-
cleanUpHandlers = () =>
157+
Action cleanUpHandlers = () =>
164158
{
165159
this.PART_NegativeButton.Click -= negativeHandler;
166160
this.PART_AffirmativeButton.Click -= affirmativeHandler;
@@ -174,9 +168,20 @@ internal Task<MessageDialogResult> WaitForButtonPressAsync()
174168

175169
this.KeyDown -= escapeKeyHandler;
176170

177-
cancellationTokenRegistration.Dispose();
171+
this.cancellationTokenRegistration.Dispose();
178172
};
179173

174+
this.cancellationTokenRegistration = this.DialogSettings
175+
.CancellationToken
176+
.Register(() =>
177+
{
178+
this.BeginInvoke(() =>
179+
{
180+
cleanUpHandlers();
181+
tcs.TrySetResult(this.ButtonStyle == MessageDialogStyle.Affirmative ? MessageDialogResult.Affirmative : MessageDialogResult.Negative);
182+
});
183+
});
184+
180185
negativeKeyHandler = (sender, e) =>
181186
{
182187
if (e.Key == Key.Enter)

src/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,19 @@ internal ProgressDialogController(ProgressDialog dialog, Func<Task> closeCallBac
4747

4848
this.WrappedDialog.Invoke(() => { this.WrappedDialog.PART_NegativeButton.Click += this.PART_NegativeButton_Click; });
4949

50-
dialog.CancellationToken.Register(() => { this.PART_NegativeButton_Click(null, new RoutedEventArgs()); });
50+
dialog.CancellationToken.Register(() => { this.WrappedDialog.BeginInvoke(this.Abort); });
5151
}
5252

5353
private void PART_NegativeButton_Click(object sender, RoutedEventArgs e)
5454
{
55-
Action action = () =>
56-
{
57-
this.IsCanceled = true;
58-
this.Canceled?.Invoke(this, EventArgs.Empty);
59-
this.WrappedDialog.PART_NegativeButton.IsEnabled = false;
60-
};
61-
this.WrappedDialog.Invoke(action);
55+
this.WrappedDialog.Invoke(this.Abort);
56+
}
57+
58+
private void Abort()
59+
{
60+
this.WrappedDialog.PART_NegativeButton.IsEnabled = false;
61+
this.IsCanceled = true;
62+
this.Canceled?.Invoke(this, EventArgs.Empty);
6263
}
6364

6465
/// <summary>

src/MahApps.Metro/Styles/Controls.ContextMenu.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<Setter Property="VerticalContentAlignment" Value="Center" />
5656
</Style>
5757

58-
<ContextMenu x:Key="MahApps.TextBox.ContextMenu" Style="{StaticResource MahApps.Styles.ContextMenu}">
58+
<ContextMenu x:Key="MahApps.TextBox.ContextMenu" Style="{StaticResource MahApps.Styles.ContextMenu}" x:Shared="False">
5959
<MenuItem Command="ApplicationCommands.Cut" Style="{DynamicResource MahApps.Styles.MenuItem}" />
6060
<MenuItem Command="ApplicationCommands.Copy" Style="{DynamicResource MahApps.Styles.MenuItem}" />
6161
<MenuItem Command="ApplicationCommands.Paste" Style="{DynamicResource MahApps.Styles.MenuItem}" />

src/MahApps.Metro/Styles/VS/ContextMenu.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<Setter Property="VerticalContentAlignment" Value="Center" />
5656
</Style>
5757

58-
<ContextMenu x:Key="MahApps.TextBox.ContextMenu" Style="{StaticResource MahApps.Styles.ContextMenu.VisualStudio}">
58+
<ContextMenu x:Key="MahApps.TextBox.ContextMenu" Style="{StaticResource MahApps.Styles.ContextMenu.VisualStudio}" x:Shared="False">
5959
<MenuItem Command="ApplicationCommands.Cut" Style="{DynamicResource MahApps.Styles.MenuItem.VisualStudio}" />
6060
<MenuItem Command="ApplicationCommands.Copy" Style="{DynamicResource MahApps.Styles.MenuItem.VisualStudio}" />
6161
<MenuItem Command="ApplicationCommands.Paste" Style="{DynamicResource MahApps.Styles.MenuItem.VisualStudio}" />

0 commit comments

Comments
 (0)