Skip to content

Commit 35d6a93

Browse files
committed
fix: TargetPropertyPath is not releasing its WeakReference properly
1 parent 9c6b8d2 commit 35d6a93

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,13 @@ public void When_IList_TabView()
726726
Assert.AreEqual(2, tabView1.TabItems.Count);
727727
}
728728

729+
[TestMethod]
730+
public void When_StateTrigger_PropertyPath()
731+
{
732+
var s = GetContent(nameof(When_StateTrigger_PropertyPath));
733+
var r = Windows.UI.Xaml.Markup.XamlReader.Load(s) as UserControl;
734+
}
735+
729736
private string GetContent(string testName)
730737
{
731738
var assembly = this.GetType().Assembly;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<UserControl
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
>
5+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
6+
<VisualStateManager.VisualStateGroups>
7+
<VisualStateGroup>
8+
<VisualState>
9+
<VisualState.StateTriggers>
10+
<!--VisualState to be triggered when window width is >=720 effective pixels.-->
11+
<StateTrigger IsActive="True"/>
12+
</VisualState.StateTriggers>
13+
<VisualState.Setters>
14+
<Setter Target="myPanel.Orientation" Value="Horizontal"/>
15+
</VisualState.Setters>
16+
</VisualState>
17+
</VisualStateGroup>
18+
</VisualStateManager.VisualStateGroups>
19+
<StackPanel x:Name="myPanel" Orientation="Vertical">
20+
<TextBlock Text="This is a block of text. It is text block 1. "
21+
Style="{ThemeResource BodyTextBlockStyle}"/>
22+
<TextBlock Text="This is a block of text. It is text block 2. "
23+
Style="{ThemeResource BodyTextBlockStyle}"/>
24+
<TextBlock Text="This is a block of text. It is text block 3. "
25+
Style="{ThemeResource BodyTextBlockStyle}"/>
26+
</StackPanel>
27+
</Grid>
28+
</UserControl>

src/Uno.UI/UI/Xaml/TargetPropertyPath.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,31 @@ namespace Windows.UI.Xaml
1010
{
1111
public sealed partial class TargetPropertyPath
1212
{
13+
#if UNO_HAS_UIELEMENT_IMPLICIT_PINNING
1314
private ManagedWeakReference? _targetRef;
15+
#endif
1416

1517
public object? Target
1618
{
19+
#if UNO_HAS_UIELEMENT_IMPLICIT_PINNING
1720
get => _targetRef?.Target;
1821
set
1922
{
2023
if (_targetRef != null)
2124
{
2225
WeakReferencePool.ReturnWeakReference(this, _targetRef);
26+
_targetRef = null;
2327
}
24-
else
28+
29+
if (!(value is null))
2530
{
2631
_targetRef = WeakReferencePool.RentWeakReference(this, value);
2732
}
2833
}
34+
#else
35+
get;
36+
set;
37+
#endif
2938
}
3039

3140
public PropertyPath? Path

0 commit comments

Comments
 (0)