Skip to content

Commit

Permalink
fix: Restore Setter Value generation outside styles (behavior should …
Browse files Browse the repository at this point in the history
…be revised in future)
  • Loading branch information
Youssef1313 committed Apr 5, 2024
1 parent 6bf6da6 commit 6adfa1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void InitializeComponent()
new global::Microsoft.UI.Xaml.Setter
{
Target = new global::Microsoft.UI.Xaml.TargetPropertyPath(this._TheListViewSubject, "Background"),
Value = new global::Microsoft.UI.Xaml.Media.SolidColorBrush(global::Microsoft.UI.Colors.Red),
Value = @"Red",
// Source 0\MainPage.xaml (Line 27:12)
}
);
Expand Down Expand Up @@ -242,7 +242,7 @@ private void InitializeComponent()
new global::Microsoft.UI.Xaml.Setter
{
Target = new global::Microsoft.UI.Xaml.TargetPropertyPath(this._TheListViewSubject, "Background"),
Value = new global::Microsoft.UI.Xaml.Media.SolidColorBrush(global::Microsoft.UI.Colors.Green),
Value = @"Green",
// Source 0\MainPage.xaml (Line 35:12)
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5097,32 +5097,6 @@ private string BuildFontWeight(string memberValue)
return _metadataHelper.FindPropertyTypeByOwnerSymbol(_currentStyleTargetType, property);
}

private INamedTypeSymbol? GetTypeForSetterTarget(string target, XamlMemberDefinition? owner)
{
var ownerControl = GetControlOwner(owner?.Owner);
if (ownerControl != null)
{
// This builds property setters for specified member setter.
var separatorIndex = target.IndexOf(".", StringComparison.Ordinal);
var elementName = target.Substring(0, separatorIndex);
var targetElement = FindSubElementByName(ownerControl, elementName);
if (targetElement != null)
{
var propertyName = target.Substring(separatorIndex + 1);
// Attached properties need to be expanded using the namespace, otherwise the resolution will be
// performed at runtime at a higher cost.
propertyName = RewriteAttachedPropertyPath(propertyName);
return _metadataHelper.FindPropertyTypeByOwnerSymbol(FindType(targetElement.Type), propertyName);
}
else
{
return null;
}
}

throw new InvalidOperationException("GetControlOwner returned null.");
}

private string BuildDependencyProperty(string property)
{
property = property.Trim('(', ')');
Expand Down Expand Up @@ -5529,9 +5503,10 @@ Func<XamlMemberDefinition, bool> propertyPredicate
{
setterPropertyType = GetDependencyPropertyTypeForSetter(setterPropertyName);
}
else if (GetMember(member.Owner, "Target") is { Value: string setterTarget })
else if (_currentStyleTargetType is not null && GetMember(member.Owner, "Target") is { Value: string setterTarget })
{
setterPropertyType = _currentStyleTargetType is null ? GetTypeForSetterTarget(setterTarget, member) : GetDependencyPropertyTypeForSetter(setterTarget);
// TODO: Confirm if (or not) we need to find the type even if we are not in a Style.
setterPropertyType = GetDependencyPropertyTypeForSetter(setterTarget);
}
}
else if (member.Owner?.Type.Name == "Setter" && member.Member.Name == "Target" && _currentStyleTargetType is not null)
Expand Down

0 comments on commit 6adfa1b

Please sign in to comment.