不知道为什么会这样...
为了清楚起见,我正在简化我的问题。我有两个参与数据绑定的变量。一个变量可以很好地获取,但另一个变量没有获取。
示例.xaml.cs:
public partial class Example : UserControl
{
private string _name;
private string _area;
private AppClass _app;
public Example(string name, AppClass app)
{
InitializeComponent();
_name = name;
_app = app;
this.DataContext = this;
InitializeData();
}
private void InitializeData()
{
if (_app != null)
{
_area = _app.GetArea();
}
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Area
{
get { return _area; }
set { _area = value; }
}
}
还有我的 Example.xaml(只是感兴趣的行):
<TextBlock Grid.Row='0' Grid.Column ='0' Padding='5,0,0,0' Background='LightBlue' Text='Exchanger'/>
<TextBlock Grid.Row='0' Grid.Column ='1' Background='LightBlue' Text="{Binding Name}" TextAlignment='Center'/>
<TextBlock Grid.Row='2' Grid.Column ='0' Padding='5,0,0,0' Background='LightCyan' Text='Area'/>
<TextBlock Grid.Row='2' Grid.Column ='1' Background='LightCyan' Text="{Binding Area}" TextAlignment='Center'/>
有趣的是,Area
被称为罚款,但Name
没有。Name
我在and的 getter 上放了一个断点Area
,它在Area
but not上中断Name
。我很困惑...