• 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


  • 相关阅读:
    3.node.js AssertionError: false == true错误解决
    9.获取当前时区时间和utc时间的工具方法
    2.Express封装mysq方法
    1.Express初识
    poj 3617
    前缀和
    pop 反序列化
    Reverse前两个题
    前两个Web题
    Misc
  • 原文地址:https://www.cnblogs.com/baobao2010/p/2152067.html
Copyright © 2020-2023  润新知