I'm new to Xamarin forms.
I'm trying to implement a switch in a registration page, that when toggled, it should show 3 more entries on the same page, if not, it just shows the first 3 entries (email, password and confirmPassword).
I'm using MVVM so I already have the RegistraPageViewModel created and would love to keep using this architecture.
Attached images are what I want to accomplish with the registration page before and after toggling the switch. Code below of the RegistrationPage.xaml (only the section pertinent to the question)
<StackLayout Orientation="Horizontal" Spacing="10">
<Label Text="Are you a service provider?"/>
<Label Text="Yes/No"/>
<Switch x:Name="SwitchIsToggled" HorizontalOptions="CenterAndExpand"
OnColor="Orange"
IsToggled="False"
ThumbColor="{StaticResource MainButtonColor}"
/>
</StackLayout>
<StackLayout x:Name="IsProvider" IsVisible="{Binding SwitchIsToggled}">
<StackLayout.Triggers>
<DataTrigger TargetType="StackLayout"
Binding="{Binding Source={x:Reference IsProvider}}">
<Setter Property="IsVisible" Value="false"/>
</DataTrigger>
</StackLayout.Triggers>
<Entry x:Name="providerCompanyEntry"
Placeholder="Company Name"
Keyboard="Default"/>
<Entry x:Name="timEntry"
Placeholder="TIN"
Keyboard="Numeric"/>
<Entry x:Name="addressEntry"
Placeholder="Address"
Keyboard="Default"/>
</StackLayout>
You just need to bind the
IsVisible
propery ofEntry
to theIsToggled
property of theSwitch
.somethig like :
Update :
xaml: