Skip to content

Commit 4bc759e

Browse files
committed
fix conflict between routed and attached, routed dialog close event.
1 parent 7979580 commit 4bc759e

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

MainDemo.Wpf/Dialogs.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<StackPanel Grid.Column="1" Grid.Row="1" VerticalAlignment="Center">
101101
<!--the request to open the dialog will bubble up to the top-most DialogHost, but we can used the attached property based event to handle the response -->
102102
<Button Command="{x:Static wpf:DialogHost.OpenDialogCommand}"
103-
wpf:DialogHost.DialogClosing="Sample2_DialogHost_OnDialogClosing"
103+
wpf:DialogHost.DialogClosingAttached="Sample2_DialogHost_OnDialogClosing"
104104
Width="128">
105105
<Button.CommandParameter>
106106
<StackPanel Margin="16">

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,22 @@ public event DialogClosingEventHandler DialogClosing
209209
add { AddHandler(DialogClosingEvent, value); }
210210
remove { RemoveHandler(DialogClosingEvent, value); }
211211
}
212-
212+
213213
/// <summary>
214214
/// Attached property which can be used on the <see cref="Button"/> which instigated the <see cref="OpenDialogCommand"/> to process the closing event.
215215
/// </summary>
216-
public static readonly DependencyProperty DialogClosingProperty = DependencyProperty.RegisterAttached(
217-
"DialogClosing", typeof (DialogClosingEventHandler), typeof (DialogHost), new PropertyMetadata(default(DialogClosingEventHandler)));
216+
public static readonly DependencyProperty DialogClosingAttachedProperty = DependencyProperty.RegisterAttached(
217+
"DialogClosingAttached", typeof (DialogClosingEventHandler), typeof (DialogHost), new PropertyMetadata(default(DialogClosingEventHandler)));
218218

219-
public static void SetDialogClosing(DependencyObject element, DialogClosingEventHandler value)
219+
public static void SetDialogClosingAttached(DependencyObject element, DialogClosingEventHandler value)
220220
{
221-
element.SetValue(DialogClosingProperty, value);
221+
element.SetValue(DialogClosingAttachedProperty, value);
222222
}
223223

224-
public static DialogClosingEventHandler GetDialogClosing(DependencyObject element)
224+
public static DialogClosingEventHandler GetDialogClosingAttached(DependencyObject element)
225225
{
226-
return (DialogClosingEventHandler) element.GetValue(DialogClosingProperty);
227-
}
226+
return (DialogClosingEventHandler) element.GetValue(DialogClosingAttachedProperty);
227+
}
228228

229229
public static readonly DependencyProperty DialogClosingCallbackProperty = DependencyProperty.Register(
230230
"DialogClosingCallback", typeof (DialogClosingEventHandler), typeof (DialogHost), new PropertyMetadata(default(DialogClosingEventHandler)));
@@ -239,9 +239,7 @@ public DialogClosingEventHandler DialogClosingCallback
239239
}
240240

241241
protected void OnDialogClosing(DialogClosingEventArgs eventArgs)
242-
{
243-
eventArgs.RoutedEvent = DialogClosingEvent;
244-
eventArgs.Source = eventArgs.Source ?? this;
242+
{
245243
RaiseEvent(eventArgs);
246244
}
247245

@@ -252,7 +250,7 @@ private void OpenDialogHandler(object sender, ExecutedRoutedEventArgs executedRo
252250
var dependencyObject = executedRoutedEventArgs.OriginalSource as DependencyObject;
253251
if (dependencyObject != null)
254252
{
255-
_attachedDialogClosingEventHandler = GetDialogClosing(dependencyObject);
253+
_attachedDialogClosingEventHandler = GetDialogClosingAttached(dependencyObject);
256254
}
257255

258256
if (executedRoutedEventArgs.Parameter != null)
@@ -279,17 +277,17 @@ private void CloseDialogHandler(object sender, ExecutedRoutedEventArgs executedR
279277
{
280278
if (executedRoutedEventArgs.Handled) return;
281279

282-
var dialogClosingEventArgs = new DialogClosingEventArgs(executedRoutedEventArgs.Parameter, DialogContent);
280+
var dialogClosingEventArgs = new DialogClosingEventArgs(executedRoutedEventArgs.Parameter, DialogContent, DialogClosingEvent);
283281

284282
//multiple ways of calling back that the dialog is closing:
283+
// * routed event
285284
// * the attached property (which should be applied to the button which opened the dialog
286285
// * straight forward dependency property
287286
// * handler provided to the async show method
288-
// * routed event
287+
OnDialogClosing(dialogClosingEventArgs);
289288
_attachedDialogClosingEventHandler?.Invoke(this, dialogClosingEventArgs);
290289
DialogClosingCallback?.Invoke(this, dialogClosingEventArgs);
291290
_asyncShowClosingEventHandler?.Invoke(this, dialogClosingEventArgs);
292-
OnDialogClosing(dialogClosingEventArgs);
293291

294292
if (!dialogClosingEventArgs.IsCancelled)
295293
SetCurrentValue(IsOpenProperty, false);

0 commit comments

Comments
 (0)