Skip to content

Commit

Permalink
fix: TargetPropertyPath is not releasing its WeakReference properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jan 20, 2021
1 parent 9c6b8d2 commit 35d6a93
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,13 @@ public void When_IList_TabView()
Assert.AreEqual(2, tabView1.TabItems.Count);
}

[TestMethod]
public void When_StateTrigger_PropertyPath()
{
var s = GetContent(nameof(When_StateTrigger_PropertyPath));
var r = Windows.UI.Xaml.Markup.XamlReader.Load(s) as UserControl;
}

private string GetContent(string testName)
{
var assembly = this.GetType().Assembly;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<!--VisualState to be triggered when window width is >=720 effective pixels.-->
<StateTrigger IsActive="True"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="myPanel.Orientation" Value="Horizontal"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel x:Name="myPanel" Orientation="Vertical">
<TextBlock Text="This is a block of text. It is text block 1. "
Style="{ThemeResource BodyTextBlockStyle}"/>
<TextBlock Text="This is a block of text. It is text block 2. "
Style="{ThemeResource BodyTextBlockStyle}"/>
<TextBlock Text="This is a block of text. It is text block 3. "
Style="{ThemeResource BodyTextBlockStyle}"/>
</StackPanel>
</Grid>
</UserControl>
11 changes: 10 additions & 1 deletion src/Uno.UI/UI/Xaml/TargetPropertyPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@ namespace Windows.UI.Xaml
{
public sealed partial class TargetPropertyPath
{
#if UNO_HAS_UIELEMENT_IMPLICIT_PINNING
private ManagedWeakReference? _targetRef;
#endif

public object? Target
{
#if UNO_HAS_UIELEMENT_IMPLICIT_PINNING
get => _targetRef?.Target;
set
{
if (_targetRef != null)
{
WeakReferencePool.ReturnWeakReference(this, _targetRef);
_targetRef = null;
}
else

if (!(value is null))
{
_targetRef = WeakReferencePool.RentWeakReference(this, value);
}
}
#else
get;
set;
#endif
}

public PropertyPath? Path
Expand Down

0 comments on commit 35d6a93

Please sign in to comment.