Skip to content

Commit bc6402a

Browse files
committed
bring event naming more inline with WPF/Popup standards
1 parent aef084c commit bc6402a

File tree

3 files changed

+63
-66
lines changed

3 files changed

+63
-66
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
PlacementMode="BottomAndAlignCentres"
8282
ToolTipService.Placement="Right"
8383
ToolTip="PopupBox, Style MaterialDesignMultiFloatingActionPopupBox"
84-
OnPopupOpened="PopupBox_OnPopupOpened"
85-
OnPopupClosed="PopupBox_OnPopupClosed">
84+
Opened="PopupBox_OnOpened"
85+
Closed="PopupBox_OnClosed">
8686
<StackPanel>
8787
<Button ToolTip="One">1</Button>
8888
<Button ToolTip="Two">2</Button>

MainDemo.Wpf/Buttons.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
4040
Console.WriteLine("Just checking we haven't suppressed the button.");
4141
}
4242

43-
private void PopupBox_OnPopupOpened(object sender, RoutedEventArgs e)
43+
private void PopupBox_OnOpened(object sender, RoutedEventArgs e)
4444
{
4545
Console.WriteLine("Just making sure the popup has opened.");
4646
}
4747

48-
private void PopupBox_OnPopupClosed(object sender, RoutedEventArgs e)
48+
private void PopupBox_OnClosed(object sender, RoutedEventArgs e)
4949
{
5050
Console.WriteLine("Just making sure the popup has closed.");
5151
}

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -242,31 +242,18 @@ private static void IsPopupOpenPropertyChangedCallback(DependencyObject dependen
242242
else
243243
Mouse.Capture(null);
244244
}
245-
246-
if (newValue)
247-
{
248-
var popupOpenedEventArgs = new RoutedEventArgs()
249-
{
250-
RoutedEvent = OnPopupOpenedEvent,
251-
Source = popupBox
252-
};
253-
popupBox.RaiseEvent(popupOpenedEventArgs);
254-
}
255-
else
256-
{
257-
var popupClosedEventArgs = new RoutedEventArgs()
258-
{
259-
RoutedEvent = OnPopupClosedEvent,
260-
Source = popupBox
261-
};
262-
popupBox.RaiseEvent(popupClosedEventArgs);
263-
}
264-
245+
265246
popupBox.AnimateChildrenIn(!newValue);
266247
popupBox._popup?.RefreshPosition();
267248

268249
VisualStateManager.GoToState(popupBox, newValue ? PopupIsOpenStateName : PopupIsClosedStateName, true);
269-
}
250+
251+
if (newValue)
252+
popupBox.OnOpened();
253+
else
254+
popupBox.OnClosed();
255+
256+
}
270257

271258
/// <summary>
272259
/// Gets or sets whether the popup is currently open.
@@ -275,46 +262,7 @@ public bool IsPopupOpen
275262
{
276263
get { return (bool) GetValue(IsPopupOpenProperty); }
277264
set { SetValue(IsPopupOpenProperty, value); }
278-
}
279-
280-
/// <summary>
281-
/// Event corresponds to the popup opening
282-
/// </summary>
283-
public static readonly RoutedEvent OnPopupOpenedEvent =
284-
EventManager.RegisterRoutedEvent(
285-
"OnPopupOpened",
286-
RoutingStrategy.Bubble,
287-
typeof(RoutedEventHandler),
288-
typeof(PopupBox));
289-
290-
/// <summary>
291-
/// Event corresponds to the popup closing
292-
/// </summary>
293-
public static readonly RoutedEvent OnPopupClosedEvent =
294-
EventManager.RegisterRoutedEvent(
295-
"OnPopupClosed",
296-
RoutingStrategy.Bubble,
297-
typeof(RoutedEventHandler),
298-
typeof(PopupBox));
299-
300-
/// <summary>
301-
/// Add / Remove OnPopupOpenedEvent handler
302-
/// </summary>
303-
public event RoutedEventHandler OnPopupOpened
304-
{
305-
add { AddHandler(OnPopupOpenedEvent, value); }
306-
remove { RemoveHandler(OnPopupOpenedEvent, value); }
307-
}
308-
309-
/// <summary>
310-
/// Add / Remove OnPopupClosedEvent handler
311-
/// </summary>
312-
public event RoutedEventHandler OnPopupClosed
313-
{
314-
add { AddHandler(OnPopupClosedEvent, value); }
315-
remove { RemoveHandler(OnPopupClosedEvent, value); }
316-
}
317-
265+
}
318266

319267
public static readonly DependencyProperty StaysOpenProperty = DependencyProperty.Register(
320268
nameof(StaysOpen), typeof (bool), typeof (PopupBox), new PropertyMetadata(default(bool)));
@@ -388,7 +336,6 @@ public Orientation UnfurlOrientation
388336
[Category("Behavior")]
389337
public event RoutedEventHandler ToggleCheckedContentClick { add { AddHandler(ToggleCheckedContentClickEvent, value); } remove { RemoveHandler(ToggleCheckedContentClickEvent, value); } }
390338

391-
392339
/// <summary>
393340
/// Raises <see cref="ToggleCheckedContentClickEvent"/>.
394341
/// </summary>
@@ -398,6 +345,56 @@ protected virtual void OnToggleCheckedContentClick()
398345
RaiseEvent(newEvent);
399346
}
400347

348+
public static readonly RoutedEvent OpenedEvent =
349+
EventManager.RegisterRoutedEvent(
350+
"Opened",
351+
RoutingStrategy.Bubble,
352+
typeof(EventHandler),
353+
typeof(PopupBox));
354+
355+
/// <summary>
356+
/// Raised when the popup is opened.
357+
/// </summary>
358+
public event RoutedEventHandler Opened
359+
{
360+
add { AddHandler(OpenedEvent, value); }
361+
remove { RemoveHandler(OpenedEvent, value); }
362+
}
363+
364+
/// <summary>
365+
/// Raises <see cref="OpenedEvent"/>.
366+
/// </summary>
367+
protected virtual void OnOpened()
368+
{
369+
var newEvent = new RoutedEventArgs(OpenedEvent, this);
370+
RaiseEvent(newEvent);
371+
}
372+
373+
public static readonly RoutedEvent ClosedEvent =
374+
EventManager.RegisterRoutedEvent(
375+
"Closed",
376+
RoutingStrategy.Bubble,
377+
typeof(EventHandler),
378+
typeof(PopupBox));
379+
380+
/// <summary>
381+
/// Raised when the popup is opened.
382+
/// </summary>
383+
public event RoutedEventHandler Closed
384+
{
385+
add { AddHandler(ClosedEvent, value); }
386+
remove { RemoveHandler(ClosedEvent, value); }
387+
}
388+
389+
/// <summary>
390+
/// Raises <see cref="ClosedEvent"/>.
391+
/// </summary>
392+
protected virtual void OnClosed()
393+
{
394+
var newEvent = new RoutedEventArgs(ClosedEvent, this);
395+
RaiseEvent(newEvent);
396+
}
397+
401398
public override void OnApplyTemplate()
402399
{
403400
if (_popup != null)

0 commit comments

Comments
 (0)