0
我刚开始工作的地铁应用程序,我面临的问题是调度不更新用户界面。我的代码如下,请让我知道是什么问题?Metro UI不更新
public class Test : DependencyObject
{
public static readonly DependencyProperty CurrentItemProperty =
DependencyProperty.Register("NameOfPerson", typeof(string), typeof(Test), null);
public String NameOfPerson
{
get
{
return (string)GetValue(CurrentItemProperty);
}
set
{
runmethod(value);
}
}
public async void runmethod(String text)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>
{
SetValue(CurrentItemProperty, text);
}
);
}
}
在主页我有一个事件按钮,当火灾更新文本框时点击。
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Test t = new Test();
t.NameOfPerson = "Hello Umar";
}
MainPage.xaml中像这样
<Page
x:Class="TestApplication.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApplication"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Button" HorizontalAlignment="Left" Margin="207,187,0,0" VerticalAlignment="Top" Height="80" Width="255" Click="Button_Click_2"/>
<TextBox x:Name="textB" Text="{Binding NameOfPerson}" HorizontalAlignment="Left" Height="80" Margin="730,187,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="307"/>
</Grid>
</Page>
谢谢。但文本框的值仍然是空的,而不是显示hello umar。 – Umar 2013-04-24 14:40:48
如果你这样做,在runmethod()'async'(或者'runmethod()')中没有任何意义。 – svick 2013-04-24 16:36:18
仍然无法正常工作。只要考虑我的代码即可显示。这是我的应用程序的完整代码。不要去更多的细节。简单的是,当按钮点击我的UI更新。我需要这个功能。 – Umar 2013-04-24 17:25:38