-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend
.Bind()
to Support TypedBinding (#156)
* Add TypedBindingExtensions * Update StoryDataTemplate.cs * Update TypedBindingExtensions.cs * Update TypedBindingExtensions.cs * Update TypedBindingExtensions.cs * Update TypedBindingExtensions.cs * Add Unit Tests * `dotnet format` * Remove duplicate code * Add Handlers, Change default value of `BindingMode mode = BindingMode.Default` * Update TypedBindingExtensionsTests.cs * `dotnet format` * Update Sample * Update TypedBindingExtensions.cs * Remove `string propertyName` * Update TypedBindingExtensions.cs * Improve Handlers * Update Bindings * Add Handlers Support * Update TypedBindingExtensionsTests.cs * Remove Non-required Generic Parameters * `dotnet format` * `dotnet format` * Add `ConfirmReadOnlyTypedBindingWithConversion` Test * Remove unnecessary `const` --------- Co-authored-by: Shaun Lawrence <[email protected]>
- Loading branch information
Showing
38 changed files
with
764 additions
and
185 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
118 changes: 59 additions & 59 deletions
118
samples/CommunityToolkit.Maui.Markup.Sample/Pages/SettingsPage.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,60 +1,60 @@ | ||
using Microsoft.Maui.Layouts; | ||
|
||
namespace CommunityToolkit.Maui.Markup.Sample.Pages; | ||
|
||
sealed class SettingsPage : BaseContentPage<SettingsViewModel> | ||
{ | ||
public SettingsPage(SettingsViewModel settingsViewModel) : base(settingsViewModel, "Settings") | ||
{ | ||
Content = new AbsoluteLayout | ||
{ | ||
Children = | ||
{ | ||
new Image().Source("dotnet_bot.png").Opacity(0.25).IsOpaque(false).Aspect(Aspect.AspectFit) | ||
.LayoutFlags(AbsoluteLayoutFlags.SizeProportional | AbsoluteLayoutFlags.PositionProportional) | ||
.LayoutBounds(0.5, 0.5, 0.5, 0.5) | ||
.AutomationIsInAccessibleTree(false), | ||
|
||
new Label() | ||
.Text("Top Stories To Fetch") | ||
.AppThemeBinding(Label.TextColorProperty,AppStyles.BlackColor, AppStyles.PrimaryTextColorDark) | ||
.LayoutFlags(AbsoluteLayoutFlags.XProportional | AbsoluteLayoutFlags.WidthProportional) | ||
.LayoutBounds(0, 0, 1, 40) | ||
.TextCenterHorizontal() | ||
.TextBottom() | ||
.Assign(out Label topNewsStoriesToFetchLabel), | ||
|
||
new Entry { Keyboard = Keyboard.Numeric } | ||
.BackgroundColor(Colors.White) | ||
.Placeholder($"Provide a value between {SettingsService.MinimumStoriesToFetch} and {SettingsService.MaximumStoriesToFetch}", Colors.Grey) | ||
.LayoutFlags(AbsoluteLayoutFlags.XProportional | AbsoluteLayoutFlags.WidthProportional) | ||
.LayoutBounds(0.5, 45, 0.8, 40) | ||
.Behaviors(new NumericValidationBehavior | ||
{ | ||
Flags = ValidationFlags.ValidateOnValueChanged, | ||
MinimumValue = SettingsService.MinimumStoriesToFetch, | ||
MaximumValue = SettingsService.MaximumStoriesToFetch, | ||
ValidStyle = AppStyles.ValidEntryNumericValidationBehaviorStyle, | ||
InvalidStyle = AppStyles.InvalidEntryNumericValidationBehaviorStyle, | ||
}) | ||
.Bind(Entry.TextProperty, nameof(SettingsViewModel.NumberOfTopStoriesToFetch)) | ||
.TextCenter() | ||
.SemanticDescription(topNewsStoriesToFetchLabel.Text), | ||
|
||
new Label() | ||
.Bind<Label, int, int, string>( | ||
Label.TextProperty, | ||
binding1: new Binding { Source = SettingsService.MinimumStoriesToFetch }, | ||
binding2: new Binding { Source = SettingsService.MaximumStoriesToFetch }, | ||
convert: ((int minimum, int maximum) values) => string.Format(CultureInfo.CurrentUICulture, $"The number must be between {values.minimum} and {values.maximum}."), | ||
mode: BindingMode.OneTime) | ||
.LayoutFlags(AbsoluteLayoutFlags.XProportional | AbsoluteLayoutFlags.WidthProportional) | ||
.LayoutBounds(0, 90, 1, 40) | ||
.TextCenter() | ||
.AppThemeColorBinding(Label.TextColorProperty,AppStyles.BlackColor, AppStyles.PrimaryTextColorDark) | ||
.Font(size: 12, italic: true) | ||
.SemanticHint($"The minimum and maximum possible values for the {topNewsStoriesToFetchLabel.Text} field above.") | ||
} | ||
}; | ||
} | ||
using Microsoft.Maui.Layouts; | ||
|
||
namespace CommunityToolkit.Maui.Markup.Sample.Pages; | ||
|
||
sealed class SettingsPage : BaseContentPage<SettingsViewModel> | ||
{ | ||
public SettingsPage(SettingsViewModel settingsViewModel) : base(settingsViewModel, "Settings") | ||
{ | ||
Content = new AbsoluteLayout | ||
{ | ||
Children = | ||
{ | ||
new Image().Source("dotnet_bot.png").Opacity(0.25).IsOpaque(false).Aspect(Aspect.AspectFit) | ||
.LayoutFlags(AbsoluteLayoutFlags.SizeProportional | AbsoluteLayoutFlags.PositionProportional) | ||
.LayoutBounds(0.5, 0.5, 0.5, 0.5) | ||
.AutomationIsInAccessibleTree(false), | ||
|
||
new Label() | ||
.Text("Top Stories To Fetch") | ||
.AppThemeBinding(Label.TextColorProperty,AppStyles.BlackColor, AppStyles.PrimaryTextColorDark) | ||
.LayoutFlags(AbsoluteLayoutFlags.XProportional | AbsoluteLayoutFlags.WidthProportional) | ||
.LayoutBounds(0, 0, 1, 40) | ||
.TextCenterHorizontal() | ||
.TextBottom() | ||
.Assign(out Label topNewsStoriesToFetchLabel), | ||
|
||
new Entry { Keyboard = Keyboard.Numeric } | ||
.BackgroundColor(Colors.White) | ||
.Placeholder($"Provide a value between {SettingsService.MinimumStoriesToFetch} and {SettingsService.MaximumStoriesToFetch}", Colors.Grey) | ||
.LayoutFlags(AbsoluteLayoutFlags.XProportional | AbsoluteLayoutFlags.WidthProportional) | ||
.LayoutBounds(0.5, 45, 0.8, 40) | ||
.Behaviors(new NumericValidationBehavior | ||
{ | ||
Flags = ValidationFlags.ValidateOnValueChanged, | ||
MinimumValue = SettingsService.MinimumStoriesToFetch, | ||
MaximumValue = SettingsService.MaximumStoriesToFetch, | ||
ValidStyle = AppStyles.ValidEntryNumericValidationBehaviorStyle, | ||
InvalidStyle = AppStyles.InvalidEntryNumericValidationBehaviorStyle, | ||
}) | ||
.TextCenter() | ||
.SemanticDescription(topNewsStoriesToFetchLabel.Text) | ||
.Bind(Entry.TextProperty, static (SettingsViewModel vm) => vm.NumberOfTopStoriesToFetch, static (SettingsViewModel vm, int text) => vm.NumberOfTopStoriesToFetch = text), | ||
|
||
new Label() | ||
.Bind<Label, int, int, string>( | ||
Label.TextProperty, | ||
binding1: new Binding { Source = SettingsService.MinimumStoriesToFetch }, | ||
binding2: new Binding { Source = SettingsService.MaximumStoriesToFetch }, | ||
convert: ((int minimum, int maximum) values) => string.Format(CultureInfo.CurrentUICulture, $"The number must be between {values.minimum} and {values.maximum}."), | ||
mode: BindingMode.OneTime) | ||
.LayoutFlags(AbsoluteLayoutFlags.XProportional | AbsoluteLayoutFlags.WidthProportional) | ||
.LayoutBounds(0, 90, 1, 40) | ||
.TextCenter() | ||
.AppThemeColorBinding(Label.TextColorProperty,AppStyles.BlackColor, AppStyles.PrimaryTextColorDark) | ||
.Font(size: 12, italic: true) | ||
.SemanticHint($"The minimum and maximum possible values for the {topNewsStoriesToFetchLabel.Text} field above.") | ||
} | ||
}; | ||
} | ||
} |
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
2 changes: 0 additions & 2 deletions
2
src/CommunityToolkit.Maui.Markup.UnitTests/AbsoluteLayoutExtensionsTests.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
6 changes: 1 addition & 5 deletions
6
src/CommunityToolkit.Maui.Markup.UnitTests/ApplicationTestHelpers.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
2 changes: 0 additions & 2 deletions
2
src/CommunityToolkit.Maui.Markup.UnitTests/AutomationPropertiesExtensionsTests.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
4 changes: 1 addition & 3 deletions
4
src/CommunityToolkit.Maui.Markup.UnitTests/BindableLayoutExtensionsTests.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
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
6 changes: 1 addition & 5 deletions
6
src/CommunityToolkit.Maui.Markup.UnitTests/BindableObjectMultiBindExtensionsTests.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
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
8 changes: 1 addition & 7 deletions
8
src/CommunityToolkit.Maui.Markup.UnitTests/DefaultBindablePropertiesTests.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
Oops, something went wrong.