zoukankan      html  css  js  c++  java
  • SL4.数据绑定OneWay、OneTime、TwoWay

    XAML:

               <Button Name="MyButton" Content="Update"  Click="MyButton_Click"  Width="65" Height="41"></Button>
    <TextBlock Height="23" Name="tbtitle" Text="{Binding Title,Mode=OneTime}" />
    <TextBlock Height="23" Name="tbtitles" Text="{Binding Title,Mode=OneWay}" />
    <TextBlock Height="23" Name="tbprice" Text="{Binding Price,Mode=TwoWay}" />

      

    XAML.CS:

           public partial class MainPage : UserControl
    {
    Book book
    = new Book();
    public MainPage()
    {
    InitializeComponent();
    book.Title
    = "CCTV-5频道";
    book.Price
    = 12;
    tbtitles.DataContext
    = book;
    tbtitle.DataContext
    = book;
    tbprice.DataContext
    = book;
    }

    private void MyButton_Click(object sender, RoutedEventArgs e)
    {
    book.Price
    = 44;
    book.Title
    = "中华电台-5频道";
    }

      

    Bool.CS:
     

        public class Book : INotifyPropertyChanged
    {
    public event PropertyChangedEventHandler PropertyChanged;
    private string _Title;
    public string Title
    {
    get { return _Title; }
    set
    {
    _Title
    =value;
    if (PropertyChanged != null)
    {
    PropertyChanged(
    this, new PropertyChangedEventArgs("Title"));
    }
    }
    }
    private decimal _price;
    public decimal Price
    {
    get
    {
    return _price;
    }
    set
    {
    _price
    = value;
    if (PropertyChanged != null)
    {
    PropertyChanged(
    this, new PropertyChangedEventArgs("Price"));
    }
    }
    }
    }

      

    代码很简单,重点在于实体类要实现INotifyPropertyChanged


  • 相关阅读:
    笔记本连接蓝牙音箱声音异常
    fence安装中遇到的问题
    ssm整合关键
    第二章:数字系统
    第一章:计算器系统体系结构
    第二章:变量和基本类型
    第一章:开始
    第十九章:特殊工具与技术
    第十八章: 用于大型程序的工具
    第十七章:标准库特殊设施
  • 原文地址:https://www.cnblogs.com/baobao2010/p/2152067.html
Copyright © 2011-2022 走看看