【发布时间】:2014-09-07 23:50:20
【问题描述】:
我在 Windows 8.1 通用应用程序的 HubSection 中有一个 TextBlock 控件。
<TextBlock x:Name="api_enabled_label"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Text="{Binding APIinfotext}" />
现在当页面启动时,在contrustor中,有一个方法在运行。
public string APIinfotext { get; set; }
public sealed partial class MainPage : Page {
VoipMS voip_service = new VoipMS("shoukatali@hotmail.com", "Kitt0cat");
public string APIinfotext { get; set; }
public MainPage() {
this.InitializeComponent();
// disable sections until API is enabled
mainpagehub.Sections[1].IsEnabled = false;
mainpagehub.Sections[2].IsEnabled = false;
//check for API and enable sections
checkAPI();
}
private async void checkAPI() {
//irrelevant code above
switch (result) {
case "success":
APIinfotext = "Your API is connected";
break;
//irrelevant code below
}
}
那么为什么不这样做呢?我将 Textblock 的 DataContext 设置为当前类(即 MainPage 部分类),并且该属性是公共属性。
注意:今天是我在 .net 2.0 框架与 WinForms 的巨大突破之后,第一次使用带有 XAML 的 .net 4.5。
【问题讨论】:
-
缺少 INotifyPropertyChanged,查看解决方案