C# 如何更改设置Win8中的TextBlock.Text?
我的主页和设置上有文本块。我想动态更改此文本块的文本。我在设置中有确认更改的按钮:C# 如何更改设置Win8中的TextBlock.Text?,c#,text,windows-8,textblock,C#,Text,Windows 8,Textblock,我的主页和设置上有文本块。我想动态更改此文本块的文本。我在设置中有确认更改的按钮: private async void OK_Tapped(object sender, TappedRoutedEventArgs e) { _main.ChangeTbText(Common.NewName); } 其中Common.NewName-我的新文本 public void ChangeTbText(string newName) { UserTextBlock.Text = newNa
private async void OK_Tapped(object sender, TappedRoutedEventArgs e)
{
_main.ChangeTbText(Common.NewName);
}
其中Common.NewName-我的新文本
public void ChangeTbText(string newName)
{
UserTextBlock.Text = newName;
}
它的工作,但我必须刷新页面,我想做它没有刷新
编辑:
谢谢你的回答,我创造了这样的东西:
在设置中:
public event PropertyChangedEventHandler PropertyChanged;
private async void OK_Tapped(object sender, TappedRoutedEventArgs e)
{
PropertyChanged += _main.ChangeUserName;
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => OnPropertyChanged("Text")));
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
_main.ChangeUser(Common.NewName);
}
在主页上:
public void ChangeUser(string Text)
{
UserTextBlock.Text = Text;
}
调试此UserTextBlock.Text时设置为ok,但我仍需要刷新页面才能看到它 也许下面的方法可以做到:Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,new Windows.UI.Core.DispatchedHandler(()=>{OnPropertyChanged(“Text”);});你实现了inotifychanged接口吗?没有,我没有。我将尝试以下内容:)@Lolek我想您刚刚开始..所以请阅读有关数据绑定的基础知识..这将对您有所帮助..解决方案是创建主页的静态对象并在设置中使用它。