New binding extensions to UWP, winui3 and UNO #8715
cesarchefinho
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
MVVMBindingExtensions
XAML Binding Extension to Bind View Models Properties anotadded with ComponentModel.DataAnnotations Attributes
Works on UNO, WinUI3 and UWP
An Extension to XAML language that simplify markup and expand XAML capabilities by automatcaly bind control to ViewModel, display validation error messages individualy per control, and read all possible ViewModel Annotations to control without any coding
things like this
simple will be this in markup:
< PasswordBox be:MVVM.ViewModel="{x:Bind ViewModel}" be:MVVM.PropertyName="PasswordProp" / >
The be:MVM extensions make all binding to you based on anottations of view model also the be.MVVM extension use ObservableValidator and ObservablePropertyes also the be:MVVM resolve binding to indexed string array attribute of collumns errors (bug in winui3 workedarrounded by be:MVVM) also suport display error messages in TextBlock other than description property for controls that dont have Description
example:
< CheckBox x:Name="NewsletterCheckBox"
be:MVVM.ErrorControl="{x:Bind NewsletterErrorControl}"
be:MVVM.ViewModel="{x:Bind ViewModel.DadosCadastro}"
be:MVVM.PropertyName="Newsletter"
Content="I Accept receive Emails."/ >
ViewModel:
public partial class UserViewModel : MVVMBaseViewModel {
}
MVVM Bind Extensions automaticaly bind these properties based on ViewModel Annotations:
InputScope => Binded with InpuScope Based on DataTypeAttribute or from Validators or by DataFormat (9, A, etc Masks)
Header => Binded with value readed from DIsplayNameAttribute.Name
TExt / Password/ SelectedValue => Binded to property indicated by Propertyname
Description => Binded to validation error of Windows Community Toolkit ValidationObject error property
Tooltip => Binded with value Readed from DIsplayNameAttribute.Description
PlaceHolder => Binded with value Readed from DataFormat Format otherwise from DIsplayNameAttribute.Description
MaxLenght => Binded with value Readed from StringLengthAttribute or from MaxLengthAttribute
IsReadOnly => Binded with value Readed from EditableAttribute
MinValue / Minimum => Binded with value Readed from RangeAttribute
MaxValue / Maximum => Binded with value Readed from RangeAttribute
CharacterCasing => Binded with value Readed from UpperCaseAttribute / LowerCaseAttribute
Mask => Binded with value Readed from DataFormatttribute DisplayFormat
User Customization:
You can tell MVVM Binding extensions at app Startup how to Bind Controls and decect proper InputScopes using
MVVM.InputScopesOfValidators.Add { typeof (Validator), InputScopeNameValue});
and
MVVM.DataDependencyProperties.Add ( typeof (Control), DependencyPropertyOfControl});
ie: MVVM.DataDependencyProperties.Add ( typeof (CustomTextBox), CustomTextBox.TextDependencyProperty});
TODO
Make a version without reflection, to improve performance, may be using source generators
See. https://github.com/cesarchefinho/MVVMBindingExtensions
Beta Was this translation helpful? Give feedback.
All reactions