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

[F100] Add "Target" support to VisualStateManager #4924

@mattleibow

Description

@mattleibow

Summary

This probably should be in this issue (#4232), but I thought I would create a new one as this might be a smaller task.

I was porting my UWP app to Xamarin.Forms and I noticed that the VisualStateManager does not allow states to affect child controls. Take this pseudo xaml:

<Grid>
    <VisualStateManager>
        <State Name="Big">
            <!-- New feature can change children -->
            <!-- UWP style -->
            <Setter Target="myButton.Color" Value="Red" />
            <!-- WPF style -->
            <Setter TargetName="myButton" Property="Color" Value="Red" />

            <!-- Current feature only changes the current element -->
           <Setter Target="BackgroundColor" Value="Red" />
        </State>
    </VisualStateManager>

    <Button x:Name="myButton" Color="Blue" />

</Grid>

This XAML allows the VSM to modify properties on the children, not just the current element.
https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.setter.target#Windows_UI_Xaml_Setter_Target
https://docs.microsoft.com/en-us/dotnet/api/system.windows.setter.targetname?view=netframework-4.7.2#System_Windows_Setter_TargetName

API Changes

I am not sure if the UWP or the WPF route is better, but we might just be able to add a TargetName property to Setter and then instead of a this.SetProperty(PropertyName, Value) we would this.FindElement(TargetName).SetProperty(PropertyName, Value).

Intended Use Case

This will solve the issue of multiple VSM elements in a single page that responds to a single event, such as a state for a wide screen or a narrow screen, or for device orientation. One VSM can control the entire page.

The use case that I was working on was on a narrow screen, I would have 2 columns in my grid, but on a wide screen, I would have 4 and show a big header with more features.

Metadata

Metadata

Assignees

Labels

F100a/VSMblockerIssue blocks next stable release. Prioritize fixing and reviewing this issue.help wantedWe welcome community contributions to any issue, but these might be a good place to start!in-progressThis issue has an associated pull request that may resolve it!inactiveIssue is older than 6 months and needs to be retestedroadmapt/enhancement ➕up-for-grabsWe welcome community contributions to any issue, but these might be a good place to start!

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions