Hi,
I’m using SfSwitch with a style defined in App.xaml. The
colors oft he SfSwitch do not update to the right state. I use the tree states of
the control :
<buttons:SfSwitch Grid.Column="1"
IsOn="{Binding Relay1}" Style="{StaticResource SwitchStyle}" AllowIndeterminateState="True" HorizontalOptions="Start" VerticalOptions="Center"/>
I use the SfSwitch control in a ListView.
The value of the control is in ViewModel
public bool? Relay1 { get => relay1; set { relay1 = value; OnDataChanged(); } }
The whole List is downloaded at the beginning.
The style for the control is defined in App.xaml
<Style TargetType="buttons:SfSwitch" x:Key="SwitchStyle">
<Setter Property="VisualType" Value="Custom" />
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="On">
<VisualState.Setters>
<Setter Property="SwitchSettings">
<Setter.Value>
<buttons:DefaultSwitchSettings x:TypeArguments="buttons:OnState"
ThumbBorderColor="DarkGreen" ThumbColor="Green"
TrackBorderColor="DarkGreen" TrackColor="LightGreen"
BusyIndicatorColor="{StaticResource PrimaryColor}" />
</Setter.Value>
</Setter>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Off">
<VisualState.Setters>
<Setter Property="SwitchSettings">
<Setter.Value>
<buttons:DefaultSwitchSettings x:TypeArguments="buttons:OffState"
ThumbBorderColor="DarkGray" ThumbColor="White"
TrackBorderColor="DarkGray" TrackColor="LightGray"/>
</Setter.Value>
</Setter>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Indeterminate">
<VisualState.Setters>
<Setter Property="SwitchSettings">
<Setter.Value>
<buttons:DefaultSwitchSettings x:TypeArguments="buttons:IndeterminateState"
ThumbBorderColor="DarkBlue" ThumbColor="Blue"
TrackBorderColor="DarkBlue" TrackColor="LightBlue"/>
</Setter.Value>
</Setter>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
When I use the Xamarin control with two states (true/false)
the page works well. With the three states true/false/null the SfSwitch has the
problem, that the control schows the wrong colors for the state. Sometimes the
colors are Ok, but the state is wrong.
Thanks
Marian