-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish task and publish 1.2.210.0 version
1.Finish task and publish 1.2.210.0 version 2.Add shortcut action support: Create desktop shortcuts, pin to Start, pin to taskbar (still exploring) 3.Re-implemented the helper class for mouse pointer modification: CursorHelper
- Loading branch information
1 parent
cc07248
commit 6dc4a1a
Showing
50 changed files
with
1,434 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace GetStoreApp.Extensions.DataType.Enums | ||
{ | ||
public enum QuickOperationType | ||
{ | ||
DesktopShortcut = 0, | ||
StartScreen = 1, | ||
Taskbar = 2, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 114 additions & 13 deletions
127
GetStoreApp/Helpers/Controls/Extensions/CursorHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,140 @@ | ||
using Microsoft.UI.Input; | ||
using Microsoft.UI.Xaml; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace GetStoreApp.Helpers.Controls.Extensions | ||
{ | ||
/// <summary> | ||
/// 附加属性:设置指针位于控件上时显示的游标 | ||
/// </summary> | ||
public class CursorHelper | ||
public static class CursorHelper | ||
{ | ||
public static InputSystemCursorShape GetCursor(DependencyObject obj) | ||
private static object locker = new object(); | ||
private static Action<UIElement, InputCursor> setCursorFunc; | ||
private static Func<UIElement, InputCursor> getCursorFunc; | ||
|
||
public static InputSystemCursorShape? GetCursor(DependencyObject obj) | ||
{ | ||
return (InputSystemCursorShape)obj.GetValue(CursorProperty); | ||
if (obj.GetValue(CursorOverrideStateProperty) is 0) | ||
{ | ||
EnsureCursorFunctions(); | ||
var cursor = GetFrameworkElementCursor((FrameworkElement)obj); | ||
|
||
obj.SetValue(CursorOverrideStateProperty, 1); | ||
|
||
var shape = cursor switch | ||
{ | ||
InputSystemCursor inputSystemCursor => (InputSystemCursorShape?)inputSystemCursor.CursorShape, | ||
_ => null | ||
}; | ||
|
||
SetCursor(obj, shape); | ||
|
||
return shape; | ||
} | ||
|
||
return (InputSystemCursorShape?)obj.GetValue(CursorProperty); | ||
} | ||
|
||
public static void SetCursor(DependencyObject obj, InputSystemCursorShape value) | ||
public static void SetCursor(DependencyObject obj, InputSystemCursorShape? value) | ||
{ | ||
obj.SetValue(CursorProperty, value); | ||
} | ||
|
||
// Using a DependencyProperty as the backing store for CursorProperty. This enables animation, styling, binding, etc... | ||
public static readonly DependencyProperty CursorProperty = | ||
DependencyProperty.RegisterAttached("Cursor", typeof(InputSystemCursorShape), typeof(CursorHelper), new PropertyMetadata(InputSystemCursorShape.Arrow, OnPropertyChanged)); | ||
DependencyProperty.RegisterAttached("Cursor", typeof(InputSystemCursorShape?), typeof(CursorHelper), new PropertyMetadata(InputSystemCursorShape.Arrow, (s, a) => | ||
{ | ||
if (!Equals(a.NewValue, a.OldValue) && s is FrameworkElement sender) | ||
{ | ||
EnsureCursorFunctions(); | ||
|
||
if (sender.GetValue(CursorOverrideStateProperty) is int state) | ||
{ | ||
if (state == 0 || state == 1) | ||
{ | ||
sender.SetValue(CursorOverrideStateProperty, 2); | ||
} | ||
|
||
if (state == 0 || state == 2) | ||
{ | ||
var cursor = a.NewValue switch | ||
{ | ||
InputSystemCursorShape shape => InputSystemCursor.Create(shape), | ||
_ => null | ||
}; | ||
SetFrameworkElementCursor(sender, cursor); | ||
} | ||
} | ||
} | ||
})); | ||
|
||
public static readonly DependencyProperty CursorOverrideStateProperty = | ||
DependencyProperty.RegisterAttached("CursorOverrideState", typeof(int), typeof(CursorHelper), new PropertyMetadata(0)); | ||
|
||
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) | ||
private static void EnsureCursorFunctions() | ||
{ | ||
FrameworkElement element = d as FrameworkElement; | ||
if (element is not null) | ||
if (getCursorFunc == null || setCursorFunc == null) | ||
{ | ||
element.Loaded += (sender, e) => | ||
lock (locker) | ||
{ | ||
FrameworkElement element = sender as FrameworkElement; | ||
typeof(FrameworkElement).GetProperty("ProtectedCursor", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(element, InputSystemCursor.Create((InputSystemCursorShape)args.NewValue)); | ||
}; | ||
if (getCursorFunc == null || setCursorFunc == null) | ||
{ | ||
var uiElementType = typeof(UIElement); | ||
var inputCursorType = typeof(InputCursor); | ||
|
||
var protectedCursorProp = uiElementType.GetProperty("ProtectedCursor", BindingFlags.Instance | BindingFlags.NonPublic); | ||
|
||
var p1 = Expression.Parameter(uiElementType, "element"); | ||
|
||
if (getCursorFunc == null) | ||
{ | ||
var body = Expression.Property(p1, protectedCursorProp); | ||
|
||
getCursorFunc = Expression.Lambda<Func<UIElement, InputCursor>>(body, p1) | ||
.Compile(); | ||
} | ||
|
||
if (setCursorFunc == null) | ||
{ | ||
var p2 = Expression.Parameter(inputCursorType, "cursor"); | ||
|
||
var body = Expression.Assign(Expression.Property(p1, protectedCursorProp), p2); | ||
|
||
setCursorFunc = Expression.Lambda<Action<UIElement, InputCursor>>(body, p1, p2) | ||
.Compile(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void SetFrameworkElementCursor(FrameworkElement element, InputCursor cursor) | ||
{ | ||
EnsureCursorFunctions(); | ||
|
||
if (element.IsLoaded) | ||
{ | ||
setCursorFunc(element, cursor); | ||
} | ||
else | ||
{ | ||
element.Loaded += OnLoaded; | ||
} | ||
|
||
void OnLoaded(object sender, RoutedEventArgs e) | ||
{ | ||
element.Loaded -= OnLoaded; | ||
setCursorFunc(element, cursor); | ||
} | ||
} | ||
|
||
private static InputCursor GetFrameworkElementCursor(FrameworkElement element) | ||
{ | ||
EnsureCursorFunctions(); | ||
|
||
return getCursorFunc(element); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.