You just need to bind the IsVisible
propery of Entry
to the IsToggled
property of the Switch
.
somethig like :
<StackLayout>
<Switch x:Name="SwitchIsToggled" HorizontalOptions="CenterAndExpand"
OnColor="Orange"
IsToggled="False"
ThumbColor="{StaticResource MainButtonColor}"
/>
<Entry Placeholder="email"></Entry>
<Entry Placeholder="password"></Entry>
<Entry Placeholder="confirm password"></Entry>
<Entry Placeholder="Company Name" IsVisible="{Binding IsToggled}" BindingContext="{x:Reference SwitchIsToggled}"></Entry>
<Entry Placeholder="TIN" IsVisible="{Binding IsToggled}" BindingContext="{x:Reference SwitchIsToggled}"></Entry>
<Entry Placeholder="Address" IsVisible="{Binding IsToggled}" BindingContext="{x:Reference SwitchIsToggled}"></Entry>
</StackLayout>
Update :
public Page2()
{
InitializeComponent();
cname.BindingContext = SwitchIsToggled;
cname.SetBinding(Entry.IsVisibleProperty, "IsToggled");
tin.BindingContext = SwitchIsToggled;
tin.SetBinding(Entry.IsVisibleProperty, "IsToggled");
address.BindingContext = SwitchIsToggled;
address.SetBinding(Entry.IsVisibleProperty, "IsToggled");
}
xaml:
<StackLayout>
<Switch x:Name="SwitchIsToggled" HorizontalOptions="CenterAndExpand"
OnColor="Orange"
IsToggled="False"
ThumbColor="{StaticResource MainButtonColor}"
/>
<Entry Placeholder="email"></Entry>
<Entry Placeholder="password"></Entry>
<Entry Placeholder="confirm password"></Entry>
<Entry x:Name="cname" Placeholder="Company Name"></Entry>
<Entry x:Name="tin" Placeholder="TIN" ></Entry>
<Entry x:Name="address" Placeholder="Address" ></Entry>
</StackLayout>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…