-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🚧 Correct ancestor XAML memory leak #4236
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
Changes from 25 commits
357d2ba
d529d48
b2851d3
8c9890b
2f9a266
c5b2bb7
55316d4
762818c
cd475a3
27c302f
1206930
669c355
45ce6ad
547cc92
6b049eb
a529c02
f35da93
9b937b9
46e6072
eccae8a
82b2819
f99184c
48e323c
afb83c5
70c5a8e
8396bf9
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||
| // See the LICENSE file in the project root for more information. | ||||||
|
|
||||||
| using Microsoft.Toolkit.Uwp; | ||||||
| using Microsoft.Toolkit.Uwp.UI; | ||||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||||
| using System.Threading.Tasks; | ||||||
| using Windows.UI.Xaml.Controls; | ||||||
| using Windows.UI.Xaml.Markup; | ||||||
|
|
||||||
| namespace UnitTests.Extensions | ||||||
| { | ||||||
| [TestClass] | ||||||
| public class Test_FrameworkElementExtensions : VisualUITestBase | ||||||
| { | ||||||
| [Ignore] | ||||||
| [TestCategory("FrameworkElementExtensions")] | ||||||
| [TestMethod] | ||||||
| public async Task Test_Ancestor_WeakReference() | ||||||
| { | ||||||
| // Need to sim loading the control, and not just load the XAML via XamlReader | ||||||
| await App.DispatcherQueue.EnqueueAsync(async () => | ||||||
| { | ||||||
| var treeRoot = XamlReader.Load( | ||||||
| @"<Page | ||||||
| xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" | ||||||
| xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" | ||||||
| xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"" | ||||||
| xmlns:ui=""using:Microsoft.Toolkit.Uwp.UI""> | ||||||
| <Grid x:Name=""OuterGrid"" Width=""200"" Background=""Khaki""> | ||||||
| <Button x:Name=""InnerButton"" ui:FrameworkElementExtensions.AncestorType=""Grid"" /> | ||||||
| </Grid> | ||||||
| </Page>") as Page; | ||||||
|
|
||||||
| Assert.IsNotNull(treeRoot, "Could not load XAML tree."); | ||||||
| await SetTestContentAsync(treeRoot); | ||||||
|
|
||||||
| // Need to simulate loading the control (and not just rely upon XamlReader.Load) | ||||||
| var frame = new Frame(); | ||||||
| frame.Navigate(treeRoot.GetType()); | ||||||
|
||||||
| frame.Navigate(treeRoot.GetType()); | |
| await App.DispatcherQueue.EnqueueAsync(() => frame.Navigate(treeRoot.GetType())); |
Outdated
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.
| btn.SetValue(FrameworkElementExtensions.AncestorProperty, new object()); | |
| await App.DispatcherQueue.EnqueueAsync(() => btn.SetValue(FrameworkElementExtensions.AncestorProperty, new object())); |
Outdated
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.
| frame.Navigate(treeRoot.GetType()); | |
| await App.DispatcherQueue.EnqueueAsync(() => frame.Navigate(treeRoot.GetType())); |
Outdated
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.
| button.SetValue(FrameworkElementExtensions.AncestorProperty, new object()); | |
| await App.DispatcherQueue.EnqueueAsync(() => button.SetValue(FrameworkElementExtensions.AncestorProperty, new object())); |
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.
We probably want to have a value set here that we check is set below after the await SetTestContent as well, otherwise if this doesn't fire then we never know, but we want to make sure it fires, eh?
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.
By changing the type here we break using it in XAML as intended. This can be demonstrated with the
TokenizingTextBoxas it uses this feature to grab theTokenSpacingproperty from its parent.