8,735
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public class Student : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int id;
public int Id
{
get { return id; }
set
{
id = value;
if (this.PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Id"));
}
}
}
}
public MainWindow()
{
Student ylld = new Student();
this.text1.DataContext = ylld;
ylld.Id = 5;
InitializeComponent();
}
}
}
Text="{Binding 自定义类中的属性名}"
TextBlock.DataContext=自定义类