Open
Description
Current behavior
Currently on uno, MarkupExtension is used like a oneshot value-provider:
xaml: <TextBlock Text="{local:TestAsdExtensions}" />
generated:
new global::Microsoft.UI.Xaml.Controls.TextBlock { IsParsing = true, /*...*/ }
.GenericApply(__that, __nameScope, ((c0, __that, __nameScope) =>
{
c0.Text = (string)Convert.ChangeType(
(((global::Microsoft.UI.Xaml.Markup.IMarkupExtensionOverrides)new global::MarkupExtLifetime.TestAsdExtensions())
.ProvideValue(global::Uno.UI.Helpers.MarkupHelper.CreateParserContext(
c0,
typeof(global::Microsoft.UI.Xaml.Controls.TextBlock),
"Text",
typeof(object)
)))?.ToString(),
typeof(string)
);
//...
}))
the instance dies immediately
Expected behavior
the markup instance should be kept alive for at least the duration of its owner's lifetime.
How to reproduce it (as minimally and precisely as possible)
- click on "Test" button
- notice the text is updated
^ different result when comparing uno to windows
Workaround
keep a hard reference of markup-instance, and clear that when the owning target is removed from the visual-tree
Works on UWP/WinUI
Yes
Environment
Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
NuGet package version(s)
Affected platforms
WebAssembly, Android, iOS, Skia (WPF)
IDE
No response
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
on windows, it is unclear yet what the exact lifetime would be, but it seems to even outlive the TextBlock?
for context, it lived past this:
if (Content is StackPanel sp &&
sp.Children.FirstOrDefault(x => x is TextBlock) is TextBlock tb)
{
sp.Children.Remove(tb);
GC.Collect();
GC.Collect();
}