110,539
社区成员
发帖
与我相关
我的任务
分享
public class TestBindingClass
{
public int Count { get; set; }
}
public TestBindingClass MyTestBindingClass;
public MainWindow()
{
InitializeComponent();
MyTestBindingClass = new TestBindingClass()
{
Count = 0
};
txtBinding.DataContext = MyTestBindingClass;
}
private void Btn_TestBinding_Click(object sender, RoutedEventArgs e)
{
MyTestBindingClass.Count++;
}
<Button Content="TestBinding" Name="Btn_TestBinding" Click="Btn_TestBinding_Click" Margin="10"></Button>
<TextBox Name="txtBinding" Text="{Binding Count,Mode=TwoWay}" Width="100" Margin="10"></TextBox>
public class Class1:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int age = 10;
public int Age
{
get { return age; }
set
{
age = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Age"));//对Age进行监听
}
}
}
}