[UWP] Implementation of Switch.OnColor #4883
[UWP] Implementation of Switch.OnColor #4883
Conversation
if (_originalOnColor == null) | ||
_originalOnColor = frame.Value; | ||
|
||
if (Element.IsSet(Switch.OnColorProperty) && !Element.OnColor.IsDefault) |
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.
The additional IsDefault
check is needed (unfortunately) since just using IsSet
when setting Color.Default
as a value, would still return true
causing the control to disappear
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.
the color.IsDefault
is probably enough
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.
Then I'm confused. In another place, I had to use IsSet
. What is the use-case for one or the other?
private void Control_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
UpdateOnColor(); | ||
Control.Loaded -= Control_Loaded; |
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.
not sure this is required
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.
You mean using the Loaded
event? I see in the SwitchCell
(https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.UAP/CellControl.cs#L106) that it happens in the measure override. Would you rather have it there?
if (_originalOnColor == null) | ||
_originalOnColor = frame.Value; | ||
|
||
if (Element.IsSet(Switch.OnColorProperty) && !Element.OnColor.IsDefault) |
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.
the color.IsDefault
is probably enough
Seen the comments, need to find some time to process them... Will do that ASAP! Thanks! |
@jfversluis Do you have more changes pending, or is this ready for re-review? Thanks! |
Removed hardcoded opacity, now also taken from the original color. Ready for re-review now! |
Co-Authored-By: jfversluis <github@geraldversluis.nl>
Co-Authored-By: jfversluis <github@geraldversluis.nl>
* Implemented Switch.OnColor on UWP * Processed first feedback * Removed hardcoded opacity * Update Xamarin.Forms.Platform.UAP/SwitchRenderer.cs Co-Authored-By: jfversluis <github@geraldversluis.nl> * Update Xamarin.Forms.Platform.UAP/SwitchRenderer.cs Co-Authored-By: jfversluis <github@geraldversluis.nl>
* Implemented Switch.OnColor on UWP * Processed first feedback * Removed hardcoded opacity * Update Xamarin.Forms.Platform.UAP/SwitchRenderer.cs Co-Authored-By: jfversluis <github@geraldversluis.nl> * Update Xamarin.Forms.Platform.UAP/SwitchRenderer.cs Co-Authored-By: jfversluis <github@geraldversluis.nl>
} | ||
|
||
protected override bool PreventGestureBubbling { get; set; } = true; | ||
|
||
void OnControlLoaded(object sender, RoutedEventArgs e) |
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.
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.
It seems that Control.GetChildren<Windows.UI.Xaml.Controls.Grid>().FirstOrDefault()
returns null
for some reason.
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.
@paymicro thanks for prompt reply! This is a piece of xaml I'm using (first Switch is used to activate the second)
< StackLayout Orientation="Horizontal" >
< Switch x:Name="FirstSwitch" IsToggled="{Binding FirstToggled}" / >
< /StackLayout >
< StackLayout Orientation="Horizontal" IsVisible="{Binding FirstToggled}" >
< Switch x:Name="SecondSwitch" IsToggled="{Binding SecondToggled}" / >
< /StackLayout >
It seems if I use the same variable, used as IsToggled binding, somewhere else, in this case in the IsVisible binding, it breaks...
Have just created brand new XF App1, updated from nuget to the latest version from yesterday, added same xaml and it crashes.
Actually only rolling back to 3.5.0.169047 works for me, for the two 3.6 in nuget it seems to crash for such cases.
Description of Change
Implements the
Switch.OnColor
for UWP which was reported as a bug to be not workingIssues Resolved
API Changes
None
Platforms Affected
Behavioral/Visual Changes
Switch.OnColor
now actually works on UWP!Before/After Screenshots
After:
Testing Procedure
Added a case for this in the Switch Gallery app
PR Checklist