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

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

Closed
mattleibow opened this issue Jan 8, 2019 · 0 comments · Fixed by #8144
Closed

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

mattleibow opened this issue Jan 8, 2019 · 0 comments · Fixed by #8144
Assignees
Labels
a/VSM blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. F100 help wanted We welcome community contributions to any issue, but these might be a good place to start! in-progress This issue has an associated pull request that may resolve it! inactive Issue is older than 6 months and needs to be retested roadmap t/enhancement ➕ up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Milestone

Comments

@mattleibow
Copy link
Contributor

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.

@samhouts samhouts added the a/VSM label Jan 22, 2019
@samhouts samhouts added the F100 label Jun 3, 2019
@samhouts samhouts changed the title [Enhancement] Add "Target" support to VisualStateManager [F100] Add "Target" support to VisualStateManager Jun 3, 2019
@samhouts samhouts added this to the 4.2.0 milestone Jun 4, 2019
@samhouts samhouts added inactive Issue is older than 6 months and needs to be retested help wanted We welcome community contributions to any issue, but these might be a good place to start! up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! labels Jul 8, 2019
@samhouts samhouts modified the milestones: 4.4.0, 4.5.0 Jan 6, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
a/VSM blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. F100 help wanted We welcome community contributions to any issue, but these might be a good place to start! in-progress This issue has an associated pull request that may resolve it! inactive Issue is older than 6 months and needs to be retested roadmap t/enhancement ➕ up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
None yet
3 participants