Skip to content

Commit 309bf0a

Browse files
committed
Refactor Extensions
1 parent b6bf4a4 commit 309bf0a

File tree

60 files changed

+25435
-16491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+25435
-16491
lines changed

dev/DevWinUI.Controls/Common/Attach/MenuFlyoutAttach/MenuFlyoutAttach.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ private static void WaitForTemplateParts(MenuFlyoutPresenter presenter, Action<S
7373
{
7474
void handler(object s, object e)
7575
{
76-
var rootStack = DependencyObjectEx.FindDescendant(presenter, "RootStack") as StackPanel;
77-
var secondaryRepeater = DependencyObjectEx.FindDescendant(presenter, "SecondaryItemsHost") as ItemsRepeater;
78-
var mainItems = DependencyObjectEx.FindDescendant(presenter, "MainItemsPresenter") as ItemsPresenter;
76+
var rootStack = DependencyObjectExtensions.FindDescendant(presenter, "RootStack") as StackPanel;
77+
var secondaryRepeater = DependencyObjectExtensions.FindDescendant(presenter, "SecondaryItemsHost") as ItemsRepeater;
78+
var mainItems = DependencyObjectExtensions.FindDescendant(presenter, "MainItemsPresenter") as ItemsPresenter;
7979

8080
if (rootStack != null && secondaryRepeater != null && mainItems != null)
8181
{

dev/DevWinUI.Controls/Common/Extension/ContentDialogExtensions.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System.ComponentModel;
2+
3+
namespace DevWinUI;
4+
public static partial class ContentDialogWindowedExtensions
5+
{
6+
extension(ContentDialog contentDialog)
7+
{
8+
public async Task<ContentDialogResult> ShowAsWindowAsync(TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
9+
{
10+
return await ShowAsWindowAsync(contentDialog, null, true, true);
11+
}
12+
public async Task<ContentDialogResult> ShowAsWindowAsync(bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
13+
{
14+
return await ShowAsWindowAsync(contentDialog, null, isModal, true);
15+
}
16+
public async Task<ContentDialogResult> ShowAsWindowAsync(Window? ownerWindow, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
17+
{
18+
return await ShowAsWindowAsync(contentDialog, ownerWindow, true, true);
19+
}
20+
public async Task<ContentDialogResult> ShowAsWindowAsync(Window? ownerWindow, bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
21+
{
22+
return await ShowAsWindowAsync(contentDialog, ownerWindow, isModal, true);
23+
}
24+
public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
25+
{
26+
return await ShowAsWindowAsync(contentDialog, null, true, false);
27+
}
28+
public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(Window? ownerWindow, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
29+
{
30+
return await ShowAsWindowAsync(contentDialog, ownerWindow, true, false);
31+
}
32+
public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
33+
{
34+
return await ShowAsWindowAsync(contentDialog, null, isModal, false);
35+
}
36+
public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(Window? ownerWindow, bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
37+
{
38+
return await ShowAsWindowAsync(contentDialog, ownerWindow, isModal, false);
39+
}
40+
public async Task<ContentDialogResult> ShowAsWindowAsync(Window? ownerWindow, bool isModal, bool hasTitleBar, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null)
41+
{
42+
WindowedContentDialog window = new()
43+
{
44+
Title = contentDialog.Title?.ToString() ?? string.Empty,
45+
HasTitleBar = hasTitleBar,
46+
Content = contentDialog.Content,
47+
PrimaryButtonText = contentDialog.PrimaryButtonText,
48+
SecondaryButtonText = contentDialog.SecondaryButtonText,
49+
CloseButtonText = contentDialog.CloseButtonText,
50+
IsPrimaryButtonEnabled = contentDialog.IsPrimaryButtonEnabled,
51+
IsSecondaryButtonEnabled = contentDialog.IsSecondaryButtonEnabled,
52+
53+
PrimaryButtonStyle = contentDialog.PrimaryButtonStyle,
54+
SecondaryButtonStyle = contentDialog.SecondaryButtonStyle,
55+
CloseButtonStyle = contentDialog.CloseButtonStyle,
56+
57+
OwnerWindow = ownerWindow,
58+
RequestedTheme = contentDialog.RequestedTheme
59+
};
60+
61+
if (primaryClick is not null)
62+
window.PrimaryButtonClick += primaryClick;
63+
if (secondaryClick is not null)
64+
window.SecondaryButtonClick += secondaryClick;
65+
if (closeClick is not null)
66+
window.CloseButtonClick += closeClick;
67+
68+
return await window.ShowAsync(isModal);
69+
}
70+
}
71+
}

dev/DevWinUI.Controls/Common/Extension/InternalExtensions.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,6 @@ internal static double RandomNegative(this double value)
3434
else return value;
3535
}
3636

37-
internal static void CreateColorStopsWithEasingFunction(this CompositionGradientBrush compositionGradientBrush, EasingMode easingMode, float colorStopBegin, float colorStopEnd, float gap = 0.05f)
38-
{
39-
var compositor = compositionGradientBrush.Compositor;
40-
var easingFunc = new SineEase { EasingMode = easingMode };
41-
if (easingFunc != null)
42-
{
43-
for (float i = colorStopBegin; i < colorStopEnd; i += gap)
44-
{
45-
var progress = (i - colorStopBegin) / (colorStopEnd - colorStopBegin);
46-
47-
var colorStop = compositor.CreateColorGradientStop(i, Color.FromArgb((byte)(0xff * easingFunc.Ease(1 - progress)), 0, 0, 0));
48-
compositionGradientBrush.ColorStops.Add(colorStop);
49-
}
50-
}
51-
else
52-
{
53-
compositionGradientBrush.ColorStops.Add(compositor.CreateColorGradientStop(colorStopBegin, Colors.Black));
54-
}
55-
56-
compositionGradientBrush.ColorStops.Add(compositor.CreateColorGradientStop(colorStopEnd, Colors.Transparent));
57-
}
5837
private static string Unbracket(string text)
5938
{
6039
if (text.Length >= 2 &&

dev/DevWinUI.Controls/CompositionProToolkit/CompositionExtensions2.cs renamed to dev/DevWinUI.Controls/CompositionProToolkit/CompositionProExtensions.cs

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace DevWinUI;
3434
/// <summary>
3535
/// Extension Methods for Compositor
3636
/// </summary>
37-
public static partial class CompositionExtensions2
37+
public static partial class CompositionProExtensions
3838
{
3939
/// <summary>
4040
/// Creates a custom shaped Effect Brush using BackdropBrush and an IMaskSurface
@@ -334,17 +334,6 @@ public static void Add<T>(this ImplicitAnimationCollection implicitAnimationColl
334334
implicitAnimationCollection.Add(CompositionExpressionEngine.ParseExpression(key), keyframeAnimation.Animation);
335335
}
336336

337-
/// <summary>
338-
/// Gets the first descendant (of Type T) of this dependency object in the visual tree.
339-
/// </summary>
340-
/// <typeparam name="T">Type deriving from DependencyObject</typeparam>
341-
/// <param name="dependencyObject">DependencyObject whose first descendant is to be obtained.</param>
342-
/// <returns>First descendant (of Type T), if any</returns>
343-
public static T GetFirstDescendantOfType<T>(this DependencyObject dependencyObject) where T : DependencyObject
344-
{
345-
return dependencyObject.GetDescendantsOfType<T>().FirstOrDefault();
346-
}
347-
348337
/// <summary>
349338
/// Gets the descendants (of Type T) of this dependency object in the visual tree.
350339
/// </summary>
@@ -384,54 +373,4 @@ public static IEnumerable<DependencyObject> GetDescendants(this DependencyObject
384373
}
385374
}
386375
}
387-
388-
/// <summary>
389-
/// Gets the first ancestor (of Type T) of this dependency object in the visual tree.
390-
/// </summary>
391-
/// <typeparam name="T">Type deriving from DependencyObject</typeparam>
392-
/// <param name="dependencyObject">DependencyObject whose first ancestor is to be obtained.</param>
393-
/// <returns>First ancestor (of Type T), if any</returns>
394-
public static T GetFirstAncestorOfType<T>(this DependencyObject dependencyObject) where T : DependencyObject
395-
{
396-
return dependencyObject.GetAncestorsOfType<T>().FirstOrDefault();
397-
}
398-
399-
/// <summary>
400-
/// Gets the ancestors (of Type T) of this dependency object in the visual tree.
401-
/// </summary>
402-
/// <typeparam name="T">Type deriving from DependencyObject</typeparam>
403-
/// <param name="dependencyObject">DependencyObject whose ancestors are to be obtained.</param>
404-
/// <returns>Enumerable collection of ancestors (of Type T)</returns>
405-
public static IEnumerable<T> GetAncestorsOfType<T>(this DependencyObject dependencyObject) where T : DependencyObject
406-
{
407-
return dependencyObject.GetAncestors().OfType<T>();
408-
}
409-
410-
/// <summary>
411-
/// Gets the ancestors of this dependency object in the visual tree.
412-
/// </summary>
413-
/// <param name="dependencyObject">DependencyObject whose ancestors are to be obtained.</param>
414-
/// <returns>Enumerable collection of ancestors</returns>
415-
public static IEnumerable<DependencyObject> GetAncestors(this DependencyObject dependencyObject)
416-
{
417-
var parent = VisualTreeHelper.GetParent(dependencyObject);
418-
419-
while (parent != null)
420-
{
421-
yield return parent;
422-
parent = VisualTreeHelper.GetParent(parent);
423-
}
424-
}
425-
426-
/// <summary>
427-
/// Checks if this dependency object is present in the Visual Tree
428-
/// of the current window.
429-
/// </summary>
430-
/// <param name="dependencyObject">DependencyObject</param>
431-
/// <returns>True if present, otherwise False</returns>
432-
public static bool IsInVisualTree(this DependencyObject dependencyObject)
433-
{
434-
return Window.Current.Content != null &&
435-
dependencyObject.GetAncestors().Contains(Window.Current.Content);
436-
}
437376
}

0 commit comments

Comments
 (0)