【发布时间】:2016-02-17 14:18:56
【问题描述】:
我正在尝试将 xaml 中 TextBlock 的“Text”属性绑定到全局字符串,但是当我更改字符串时,TextBlock 的内容不会改变。我错过了什么?
我的 xaml:
<StackPanel>
<Button Content="Change!" Click="Button_Click" />
<TextBlock Text="{x:Bind text}" />
</StackPanel>
我的 C#:
string text;
public MainPage()
{
this.InitializeComponent();
text = "This is the original text.";
}
private void Button_Click(object sender, RoutedEventArgs e)
{
text = "This is the changed text!";
}
【问题讨论】:
-
这将永远不会更新,因为您没有引发 PropertyChanged 事件。为了更新它,创建一个静态的 DTO,并在其中包含字符串。静态 Dto 需要实现 NotifyProperty 已更改。
-
当 itemsource 不刷新时你可以试试这个解决方案:Here is Relevant Solution
标签: c# xaml win-universal-app