Skip to content

Commit

Permalink
fix: Apply x:Bind expressions in Resources
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 7, 2024
1 parent 46b7725 commit 5529e7b
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ private void BuildCompiledBindingsInitializerForTemplate(IIndentedStringBuilder
using (writer.BlockInvariant($"__fe.Loading += delegate"))
{
BuildComponentResouceBindingUpdates(writer);
BuildXBindApply(writer);
BuildxBindEventHandlerInitializers(writer, CurrentScope.xBindEventsHandlers);
}
writer.AppendLineIndented(";");
Expand Down Expand Up @@ -1117,6 +1118,19 @@ private void BuildComponentResouceBindingUpdates(IIndentedStringBuilder writer)
}
}

private void BuildXBindApply(IIndentedStringBuilder writer)
{
for (var i = 0; i < CurrentScope.Components.Count; i++)
{
var component = CurrentScope.Components[i];

if (HasXBindMarkupExtension(component.XamlObject) && IsDependencyObject(component.XamlObject))
{
writer.AppendLineIndented($"{component.MemberName}.ApplyXBind();");
}
}
}

private void BuildComponentFields(IIndentedStringBuilder writer)
{
for (var i = 0; i < CurrentScope.Components.Count; i++)
Expand Down Expand Up @@ -4229,9 +4243,11 @@ private string BuildXBindEvalFunction(XamlMemberDefinition member, XamlObjectDef

var modeMember = bindNode.Members.FirstOrDefault(m => m.Member.Name == "Mode")?.Value?.ToString() ?? GetDefaultBindMode();
var rawBindBack = bindNode.Members.FirstOrDefault(m => m.Member.Name == "BindBack")?.Value?.ToString();

var sourceInstance = CurrentResourceOwner is not null ? CurrentResourceOwnerName : "__that";

var applyBindingParameters = _isHotReloadEnabled
? "__that, (___b, __that)"
? $"{sourceInstance}, (___b, {sourceInstance})"
: "___b";

if (isInsideDataTemplate)
Expand Down Expand Up @@ -4396,7 +4412,7 @@ string buildBindBack()
? ", new [] {" + string.Join(", ", formattedPaths) + "}"
: "";

return $".BindingApply({applyBindingParameters} => /*defaultBindMode{GetDefaultBindMode()} {rawFunction}*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, __that, ___ctx => {bindFunction}, {buildBindBack()} {pathsArray}))";
return $".BindingApply({applyBindingParameters} => /*defaultBindMode{GetDefaultBindMode()} {rawFunction}*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, {sourceInstance}, ___ctx => {bindFunction}, {buildBindBack()} {pathsArray}))";
}
}

Expand Down

0 comments on commit 5529e7b

Please sign in to comment.