-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from FmgLib/132-keyboardaccelerator-support
132 keyboardaccelerator support
- Loading branch information
Showing
6 changed files
with
160 additions
and
18 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
88 changes: 88 additions & 0 deletions
88
src/FmgLib.MauiMarkup/Extensions/KeyboardAcceleratorExtension.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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace FmgLib.MauiMarkup; | ||
|
||
public static partial class KeyboardAcceleratorExtension | ||
{ | ||
public static T Key<T>(this T self, | ||
string key) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
self.SetValue(Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty, key); | ||
return self; | ||
} | ||
|
||
public static T Key<T>(this T self, | ||
Func<string> configure) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
var key = configure(); | ||
self.SetValue(Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty, key); | ||
return self; | ||
} | ||
|
||
public static T Key<T>(this T self, Func<PropertyContext<string>, IPropertyBuilder<string>> configure) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
var context = new PropertyContext<string>(self, Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty); | ||
configure(context).Build(); | ||
return self; | ||
} | ||
|
||
public static SettersContext<T> Key<T>(this SettersContext<T> self, | ||
string key) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty, Value = key }); | ||
return self; | ||
} | ||
|
||
public static SettersContext<T> Key<T>(this SettersContext<T> self, Func<PropertySettersContext<string>, IPropertySettersBuilder<string>> configure) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
var context = new PropertySettersContext<string>(self.XamlSetters, Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty); | ||
configure(context).Build(); | ||
return self; | ||
} | ||
|
||
public static T Modifiers<T>(this T self, | ||
Microsoft.Maui.KeyboardAcceleratorModifiers modifiers) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
self.SetValue(Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty, modifiers); | ||
return self; | ||
} | ||
|
||
public static T Modifiers<T>(this T self, | ||
Func<Microsoft.Maui.KeyboardAcceleratorModifiers> configure) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
var modifiers = configure(); | ||
self.SetValue(Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty, modifiers); | ||
return self; | ||
} | ||
|
||
public static T Modifiers<T>(this T self, Func<PropertyContext<Microsoft.Maui.KeyboardAcceleratorModifiers>, IPropertyBuilder<Microsoft.Maui.KeyboardAcceleratorModifiers>> configure) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
var context = new PropertyContext<Microsoft.Maui.KeyboardAcceleratorModifiers>(self, Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty); | ||
configure(context).Build(); | ||
return self; | ||
} | ||
|
||
public static SettersContext<T> Modifiers<T>(this SettersContext<T> self, | ||
Microsoft.Maui.KeyboardAcceleratorModifiers modifiers) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty, Value = modifiers }); | ||
return self; | ||
} | ||
|
||
public static SettersContext<T> Modifiers<T>(this SettersContext<T> self, Func<PropertySettersContext<Microsoft.Maui.KeyboardAcceleratorModifiers>, IPropertySettersBuilder<Microsoft.Maui.KeyboardAcceleratorModifiers>> configure) | ||
where T : Microsoft.Maui.Controls.KeyboardAccelerator | ||
{ | ||
var context = new PropertySettersContext<Microsoft.Maui.KeyboardAcceleratorModifiers>(self.XamlSetters, Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty); | ||
configure(context).Build(); | ||
return self; | ||
} | ||
|
||
} | ||
|
33 changes: 33 additions & 0 deletions
33
src/FmgLib.MauiMarkup/Extensions/MenuFlyoutItemExtension.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace FmgLib.MauiMarkup; | ||
|
||
public static partial class MenuFlyoutItemExtension | ||
{ | ||
public static T KeyboardAccelerators<T>(this T self, | ||
IList<Microsoft.Maui.Controls.KeyboardAccelerator> keyboardAccelerators) | ||
where T : Microsoft.Maui.Controls.MenuFlyoutItem | ||
{ | ||
foreach (var item in keyboardAccelerators) | ||
self.KeyboardAccelerators.Add(item); | ||
return self; | ||
} | ||
|
||
public static T KeyboardAccelerators<T>(this T self, | ||
params Microsoft.Maui.Controls.KeyboardAccelerator[] keyboardAccelerators) | ||
where T : Microsoft.Maui.Controls.MenuFlyoutItem | ||
{ | ||
foreach (var item in keyboardAccelerators) | ||
self.KeyboardAccelerators.Add(item); | ||
return self; | ||
} | ||
|
||
public static T KeyboardAccelerators<T>(this T self, | ||
Func<Microsoft.Maui.Controls.KeyboardAccelerator[]> configure) | ||
where T : Microsoft.Maui.Controls.MenuFlyoutItem | ||
{ | ||
var keyboardAccelerators = configure(); | ||
foreach (var item in keyboardAccelerators) | ||
self.KeyboardAccelerators.Add(item); | ||
return self; | ||
} | ||
|
||
} |
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