0
点赞
收藏
分享

微信扫一扫

wpf toggleSwitch 的只读属性

芝婵 2023-06-06 阅读 51

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)));
            }
        }
    }


举报

相关推荐

0 条评论