XF 开关控件
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App20"
x:Class="App20.MainPage">
<StackLayout x:Name="sl" VerticalOptions="Center">
<Switch x:Name="sw" Toggled="Switch_Toggled"></Switch>
</StackLayout>
</ContentPage>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App20
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
if (sw.IsToggled)
{
sl.BackgroundColor = Color.Red;
}
else
{
sl.BackgroundColor = Color.Yellow;
}
}
}
}