zoukankan      html  css  js  c++  java
  • wpf toggleSwitch 的只读属性

    xml code

    ---------------------------------------------

    <Page

        x:Class="UWPDemo.MainPage"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:local="using:UWPDemo"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d"

        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <Grid>

            <ToggleSwitch IsOn="{x:Bind isno, Mode=TwoWay}">on </ToggleSwitch>

            <Button Content="Button" Click="Button_Click" Margin="524,601,0,0" VerticalAlignment="Top" Width="434"/>

        </Grid>

    </Page>

    C# code

    -----------------------------------

    public sealed partial class MainPage : Page, INotifyPropertyChanged

        {

            private bool _isno;

            public event PropertyChangedEventHandler PropertyChanged;

            public bool isno

            {

                set

                {

                    if(PropertyChanged!=null)

                    {

                        PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(isno)));

                    }

                }

                get

                {

                    return _isno;

                }

            }

            public MainPage()

            {

                this.InitializeComponent();

            }

            private void Button_Click(object sender, RoutedEventArgs e)

            {

                _isno=!_isno;

                if (PropertyChanged != null)

                {

                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(isno)));

                }

            }

        }

  • 相关阅读:
    SICP学习笔记(1.3.4)
    SICP学习笔记(1.1.7 ~ 1.1.8)
    It's Not Just Standing Up: Patterns of Daily Standup Meetings
    SICP学习笔记(1.1.4~1.1.5)
    SICP学习笔记(2.1.4)
    呵呵呵,传说中的吉普赛读心术(WPF版)
    利用SendMessage实现窗口拖动
    SICP学习笔记(2.2.2)
    SICP学习笔记(2.3.1~2.3.2)
    SICP学习笔记(2.3.3)
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14244146.html
Copyright © 2011-2022 走看看