Skip to content

Commit

Permalink
fix: Adjust support for x:Bind edition
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Nov 18, 2022
1 parent 15526cb commit 5d1de36
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public record DiagnosticsResult(string Id);
var scenarioName = Path.GetFileName(scenarioFolder);
var path = Path.Combine(scenarioFolder, "Scenario.json");

//if(scenarioName != "When_Simple_Xaml_Add_xBind_Simple_Property_Update")
//{
// continue;
//}

if (File.Exists(path))
{
var scenarios = ReadScenarioConfig(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
"IsMono": false,
"PassResults": [
{
"MetadataUpdates": 0,
"Diagnostics": [
// MainPage_c2bc688a73eab5431d787dcd21fe32b9.cs(68,83): error ENC0049: Ceasing to capture variable '__that' requires restarting the application.
{ "Id": "ENC0049" }
]
"MetadataUpdates": 1,
"Diagnostics": []
}
]
},
Expand All @@ -17,11 +14,8 @@
"IsMono": true,
"PassResults": [
{
"MetadataUpdates": 0,
"Diagnostics": [
// MainPage_c2bc688a73eab5431d787dcd21fe32b9.cs(68,83): error ENC0049: Ceasing to capture variable '__that' requires restarting the application.
{ "Id": "ENC0049" }
]
"MetadataUpdates": 1,
"Diagnostics": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{
"MetadataUpdates": 0,
"Diagnostics": [
// error ENC0009: Updating the type of method requires restarting the application.
{ "Id": "ENC0009" }
]
}
Expand All @@ -18,6 +19,7 @@
{
"MetadataUpdates": 0,
"Diagnostics": [
// error ENC0009: Updating the type of method requires restarting the application.
{ "Id": "ENC0009" }
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4313,6 +4313,10 @@ private string BuildXBindEvalFunction(XamlMemberDefinition member, XamlObjectDef
? ", new [] {" + string.Join(", ", formattedPaths) + "}"
: "";

var applyBindingParameters = _isHotReloadEnabled
? "__that, (___b, __that)"
: "___b";

if (isInsideDataTemplate)
{
var dataTypeObject = FindMember(dataTemplateObject!, "DataType", XamlConstants.XamlXmlNamespace);
Expand Down Expand Up @@ -4360,7 +4364,7 @@ string buildBindBack()
}
}

return $".BindingApply(___b => /*defaultBindMode{GetDefaultBindMode()}*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, null, ___ctx => ___ctx is {GetType(dataType)} ___tctx ? (object)({contextFunction}) : null, {buildBindBack()} {pathsArray}))";
return $".BindingApply({applyBindingParameters} => /*defaultBindMode{GetDefaultBindMode()}*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, null, ___ctx => ___ctx is {GetType(dataType)} ___tctx ? (object)({contextFunction}) : null, {buildBindBack()} {pathsArray}))";
}
else
{
Expand Down Expand Up @@ -4407,7 +4411,7 @@ string buildBindBack()
}

var bindFunction = $"___ctx is {_xClassName} ___tctx ? (object)({rawFunction}) : null";
return $".BindingApply(___b => /*defaultBindMode{GetDefaultBindMode()} {originalRawFunction}*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, __that, ___ctx => {bindFunction}, {buildBindBack()} {pathsArray}))";
return $".BindingApply({applyBindingParameters} => /*defaultBindMode{GetDefaultBindMode()} {originalRawFunction}*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, __that, ___ctx => {bindFunction}, {buildBindBack()} {pathsArray}))";
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/Uno.UI/UI/Xaml/Markup/ApplyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Uno.UI.Helpers.Xaml
public static class ApplyExtensions
{
public delegate Binding BindingApplyHandler(Binding binding);
public delegate Binding BindingApplyWithParamHandler(Binding binding, object that);

/// <summary>
/// Executes the provided apply handler on the binding instance. Used by the XAML code generator.
Expand All @@ -18,6 +19,16 @@ public static Binding BindingApply(this Binding instance, BindingApplyHandler ap
return instance;
}

/// <summary>
/// Executes the provided apply handler on the binding instance. Used by the XAML code generator.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static Binding BindingApply(this Binding instance, object that, BindingApplyWithParamHandler apply)
{
apply(instance, that);
return instance;
}

/// <summary>
/// Executes the provided apply handler on the specified instance. Used by the XAML code generator.
/// </summary>
Expand Down

0 comments on commit 5d1de36

Please sign in to comment.