-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add VSM Setter TargetName #8144
Conversation
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.
cosmetic changes, then it's 👍
Xamarin.Forms.Core/Setter.cs
Outdated
{ | ||
if (target == null) | ||
throw new ArgumentNullException(nameof(target)); | ||
var targetObject = FindTargetObject(scope, TargetName); |
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.
I think the FindTargetObject doesn't bring enough value by itself
if (target == null) throw...;
if (!string.IsNullOrEmpty(TargetName) && target is Element element)
target == element.FindByName(TargetName) as BindableObject ?? throw ...;
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.
I think I implemented the way you intended, if I missed anything please let me know :)
please target 4.4.0 |
Include unit and xaml unit tests corrected naming to prevent issues Updating xamlc is still outstanding
🤦♂ done! |
Does this support property paths? For example:
I have an app that actually does this: https://gist.github.com/mattleibow/2f2f33c353be0b33e31bf9007095b105#file-mainpage-xaml-L35-L41 |
That is pretty awesome :) Just tried it with this PR and that doesn't work. XamlC falls over it, and even when I disable that it won't work. In addition I tried it with another path like Would it make sense to get this in first as a start and then build from there? |
That seems like something g that we can do still. I can always name things a bit more for now. Good work so far. Gonna be nice to write less VSM per element :) |
Description of Change
Adds the ability to target a child object by name for a Setter for visual state management or styles.
Issues Resolved
API Changes
Added:
public string TargetName { get; set; }
Platforms Affected
Behavioral/Visual Changes
None
Before/After Screenshots
Not applicable
Testing Procedure
I've added a core gallery page
VisualStateSetterTarget.xaml
which has a button to toggle the VSM state of theStackLayout
. When it's pressed, theALabel
is also triggered because of it's reference throughTargetName
.PR Checklist