Open dr1rrb opened 3 years ago
Wrote two runtime tests for this to prepare after #14936.
[TestMethod]
[RunsOnUIThread]
public async Task When_LayoutUpdated()
{
string s = "";
var button = new Button();
button.LayoutUpdated += (sender, args) =>
{
Assert.IsNull(sender);
Assert.IsNull(args);
s += "button1 ";
};
button.LayoutUpdated += (sender, args) =>
{
Assert.IsNull(sender);
Assert.IsNull(args);
s += "button2 ";
};
var border = new Border
{
Width = 100,
Height = 100,
Background = new SolidColorBrush(Colors.Red),
};
border.LayoutUpdated += (sender, args) =>
{
Assert.IsNull(sender);
Assert.IsNull(args);
s += "border1 ";
};
border.LayoutUpdated += (sender, args) =>
{
Assert.IsNull(sender);
Assert.IsNull(args);
s += "border2 ";
};
await UITestHelper.Load(border);
// On WinUI, running the test randomly produces one of these outputs.
if (s is not ("button1 button2 border1 border2 " or "border1 border2 button1 button2 "))
{
Assert.Fail($"Test failed. Actual: {s}");
}
}
[TestMethod]
[RunsOnUIThread]
public void When_LayoutUpdated_Element_Can_Get_GCed()
{
WeakReference GetButtonWeakReference()
{
var button = new Button();
button.LayoutUpdated += static (_, _) => { };
return new WeakReference(button);
}
var weakRef = GetButtonWeakReference();
GC.Collect();
Assert.IsFalse(weakRef.IsAlive);
}
Done for Skia and Wasm in #16761
Current behavior
The
LayoutUpdated
event is fired only on elements that has been [re-]layoutedExpected behavior
UIElement
associated to the current threadnull
More info: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.frameworkelement.layoutupdated?view=winrt-20348#remarks
How to reproduce it (as minimally and precisely as possible)
In a blank app, in the
MainPage
constructor, addThe event handler is never invoked while it's on UWP!
Workaround
Window.Current.Content.LayoutUpdated
to get notify also for element that are not in the visual tree.Works on UWP/WinUI
Yes
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
NuGet package version(s)
3.10.0-dev.632
Affected platforms
iOS, Android, WebAssembly, WebAssembly renderers for Xamarin.Forms, macOS, Skia (WPF), Skia (GTK on Linux/macOS/Windows), Skia (Tizen)
IDE
No response
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
Didn't really validated on all platforms ... just an assumption based of current implementation.