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.
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:
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
TargetNameproperty toSetterand then instead of athis.SetProperty(PropertyName, Value)we wouldthis.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.