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;

            }
        }
    }
}
 

 

posted @ 2018-08-06 21:40  dxm809  阅读(67)  评论(0编辑  收藏  举报