小编Dav*_*igo的帖子

WPF应用程序的意外行为

我正在学习WPF,我编写了一个使用"Bindings"概念的小例子.但该程序的行为与我的预期不同.

我有Person类,它有两个属性:FirstName和LastName.这个类实现了INotifyPropertyChanged接口,因此我可以用它来绑定.

 class Person : INotifyPropertyChanged
{
    private string firstName;
    private string lastName;

    public string FirstName
    {
        get {  return firstName; }
        set { NotifyPropertyChanged("FirstName"); firstName = value; }
    }

    public string LastName
    {
        get { return lastName; }
        set { NotifyPropertyChanged("LastName"); lastName = value; }
    }

    private void NotifyPropertyChanged(string info)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(info));
    }

    public event PropertyChangedEventHandler PropertyChanged;

}
Run Code Online (Sandbox Code Playgroud)

然后我有一些XAML代码.

<Window x:Class="BughouseClient.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <StackPanel Name="stackPanel">
        <TextBox Text="{Binding Path=FirstName, UpdateSourceTrigger=PropertyChanged}"> …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

2
推荐指数
1
解决办法
63
查看次数

标签 统计

c# ×1

wpf ×1

xaml ×1