Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Conversation

jfversluis
Copy link
Member

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

  • Core/XAML (all platforms)

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 the StackLayout. When it's pressed, the ALabel is also triggered because of it's reference through TargetName.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

Copy link
Member

@StephaneDelcroix StephaneDelcroix left a 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 👍

{
if (target == null)
throw new ArgumentNullException(nameof(target));
var targetObject = FindTargetObject(scope, TargetName);
Copy link
Member

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 ...;

Copy link
Member Author

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 :)

@samhouts samhouts requested a review from hartez November 14, 2019 18:53
@samhouts samhouts added blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. retarget-branch-required PR or associated issues target a milestone. Please target this PR to the matching branch. labels Nov 14, 2019
@samhouts
Copy link
Contributor

please target 4.4.0

@jfversluis jfversluis removed the retarget-branch-required PR or associated issues target a milestone. Please target this PR to the matching branch. label Nov 20, 2019
@jfversluis jfversluis changed the base branch from master to 4.4.0 November 20, 2019 07:41
@jfversluis
Copy link
Member Author

🤦‍♂ done!

@mattleibow
Copy link
Contributor

Does this support property paths? For example:

<Setter TargetName="ItemGrid" Property="ColumnDefinitions[2].Width" Value="0" />

I have an app that actually does this: https://gist.github.com/mattleibow/2f2f33c353be0b33e31bf9007095b105#file-mainpage-xaml-L35-L41

@jfversluis
Copy link
Member Author

jfversluis commented Nov 22, 2019

Does this support property paths? For example:

<Setter TargetName="ItemGrid" Property="ColumnDefinitions[2].Width" Value="0" />

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 Label.Background.Saturation, which also doesn't work. It only works with bindable properties at this time.

Would it make sense to get this in first as a start and then build from there?

@mattleibow
Copy link
Contributor

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 :)

@samhouts samhouts changed the base branch from 4.4.0 to master December 6, 2019 04:09
@samhouts samhouts merged commit ca1ae04 into master Dec 6, 2019
@samhouts samhouts deleted the fix-4924 branch December 6, 2019 04:10
@samhouts samhouts added this to the 4.5.0 milestone Jan 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a/style a/VSM a/Xaml </> blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. ControlGallery Core F100 roadmap t/enhancement ➕

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CollectionView SelectedItem Color [F100] Add "Target" support to VisualStateManager

7 participants