xamarin简单数据绑定实例

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace App2
{
    public partial class MainPage : ContentPage
    {

        public class TextDataModel : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;

            private string _text1;
            private string _text2;

            public string text1
            {
                get { return _text1; }
                set
                {
                    _text1 = value;
                    if (this.PropertyChanged != null)
                    {
                        this.PropertyChanged(this, new PropertyChangedEventArgs("text1"));
                    }
                }
            }

            public string text2
            {
                get { return _text2; }
                set
                {
                    _text2 = value;
                    if (this.PropertyChanged != null)
                    {
                        this.PropertyChanged(this, new PropertyChangedEventArgs("text2"));
                    }
                }
            }
        }

        public TextDataModel TextData1 = new TextDataModel();
        public TextDataModel TextData2 = new TextDataModel();

        public MainPage()
        {
            InitializeComponent();

            edit1.BindingContext = TextData1;
            label1.BindingContext = TextData1;
        }
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App2.MainPage">

    <StackLayout>
        <Editor x:Name="edit1" Text="{Binding Path=text1, Mode=OneWayToSource}"/>
        <Label x:Name="label1" Text="{Binding Path=text1, Mode=Default}" FontSize="Title"/>
        <Label x:Name="label2" FontSize="Title"/>
    </StackLayout>

</ContentPage>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值