-
Notifications
You must be signed in to change notification settings - Fork 2k
Add Binding converter culture support #35821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: net11.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| using System.Xml; | ||
|
|
||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp; | ||
| using Microsoft.Maui.Controls.Xaml; | ||
|
|
||
| using static System.String; | ||
|
|
@@ -404,10 +405,15 @@ private static bool ProvideValueForBindingExtension(ElementNode markupNode, Inde | |
| } | ||
| else | ||
| { | ||
| value = expression + | ||
| $"{{ UpdateSourceEventName = {extVariable.ValueAccessor}.UpdateSourceEventName, " + | ||
| $"FallbackValue = {extVariable.ValueAccessor}.FallbackValue, " + | ||
| $"TargetNullValue = {extVariable.ValueAccessor}.TargetNullValue }}"; | ||
| var objectInitializer = new StringBuilder() | ||
| .Append($"{{ UpdateSourceEventName = {extVariable.ValueAccessor}.UpdateSourceEventName, "); | ||
| if (markupNode.HasProperty("ConverterCulture")) | ||
| objectInitializer.Append($"ConverterCulture = {extVariable.ValueAccessor}.ConverterCulture, "); | ||
| objectInitializer | ||
| .Append($"FallbackValue = {extVariable.ValueAccessor}.FallbackValue, ") | ||
| .Append($"TargetNullValue = {extVariable.ValueAccessor}.TargetNullValue }}"); | ||
|
|
||
| value = expression + objectInitializer; | ||
| return true; | ||
| } | ||
| } | ||
|
|
@@ -441,6 +447,17 @@ private static bool ProvideValueForBindingExtension(ElementNode markupNode, Inde | |
| expression += ") {"; | ||
| if (markupNode.Properties.TryGetValue(new XmlName(null, "UpdateSourceEventName"), out var updateSourceEventNameNode)) | ||
| expression += $"UpdateSourceEventName = {getNodeValue(updateSourceEventNameNode, context.Compilation.GetTypeByMetadataName("System.String")!).ValueAccessor}, "; | ||
| if (markupNode.Properties.TryGetValue(new XmlName(null, "ConverterCulture"), out var converterCultureNode)) | ||
| { | ||
| if (converterCultureNode is ValueNode { Value: string converterCulture }) | ||
| { | ||
| expression += $"ConverterCulture = global::System.Globalization.CultureInfo.GetCultureInfo({SymbolDisplay.FormatLiteral(converterCulture, true)}), "; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The source-generated binding code instantiates a fresh
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion — addressed in e21a5d0. Literal converter culture values now emit |
||
| else | ||
| { | ||
| expression += $"ConverterCulture = {getNodeValue(converterCultureNode, context.Compilation.GetTypeByMetadataName("System.Globalization.CultureInfo")!).ValueAccessor}, "; | ||
| } | ||
| } | ||
| if (markupNode.Properties.TryGetValue(new XmlName(null, "FallbackValue"), out var fallbackValueNode)) | ||
| expression += $"FallbackValue = {getNodeValue(fallbackValueNode, context.Compilation.GetTypeByMetadataName("System.Object")!).ValueAccessor}, "; | ||
| if (markupNode.Properties.TryGetValue(new XmlName(null, "TargetNullValue"), out var targetNullValueNode)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For full parity, consider whether
ConverterCultureshould also be supported onTemplateBindingExtension, which shares much of this binding-construction path. Right nowConverterCultureis wired forBinding/MultiBindingbut aTemplateBindingwith a converter won't honor a culture. Non-blocking — flagging for completeness/consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this out intentionally for this PR.
TemplateBindingExtensioncurrently has noConverterCultureAPI surface, so adding parity there would require a separate public API addition beyond theBinding/MultiBindingsupport in scope here.