Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ListPicker中选择项目后刷新当前页面_C#_Windows Phone 7_Listpicker - Fatal编程技术网

C# 如何在ListPicker中选择项目后刷新当前页面

C# 如何在ListPicker中选择项目后刷新当前页面,c#,windows-phone-7,listpicker,C#,Windows Phone 7,Listpicker,我想知道如何使用刷新当前页面 heNavigationService.Navigate(新Uri(NavigationService.Source+“?Refresh=true”,UriKind.Relative)) 在我在ListPicker中选择一个元素后。将autopostback设置为true,示例: <asp:DropDownList OnSelectedIndexChanged="dropDown_indexChange" ID="DropDownList1" runat

我想知道如何使用刷新当前页面

heNavigationService.Navigate(新Uri(NavigationService.Source+“?Refresh=true”,UriKind.Relative))


在我在ListPicker中选择一个元素后。

将autopostback设置为true,示例:

  <asp:DropDownList  OnSelectedIndexChanged="dropDown_indexChange" ID="DropDownList1" runat="server" AutoPostBack="True">

我想您正在使用适用于Windows Phone的MVVM Light。在这种情况下,您应该捕获页面中的事件,然后在ViewModel上触发一个命令

例如:

页面后面的代码

private void Listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ViewModelClass vm = this.DataContext as ViewMoedlClass;
    if (vm != null)
    {
        vm.RefreshCommand.Execute();
    }
}
视图模型

class ViewModelClass
{
    public ViewModelClass
    {
        this.RefreshCommand = new RelayCommand(() =>
        {
            NavigationService.Navigate(new Uri(NavigationService.Source + "?Refresh=true", UriKind.Relative));
        }   
    }

    public RelayCommand RefreshCommand { get; set;}

}
<ListBox SelectionChanged="Listbox_SelectionChanged" />
Xaml

class ViewModelClass
{
    public ViewModelClass
    {
        this.RefreshCommand = new RelayCommand(() =>
        {
            NavigationService.Navigate(new Uri(NavigationService.Source + "?Refresh=true", UriKind.Relative));
        }   
    }

    public RelayCommand RefreshCommand { get; set;}

}
<ListBox SelectionChanged="Listbox_SelectionChanged" />


理论上,您不必在代码隐藏中执行此操作,您可以将ViewModel中的命令直接绑定到SelectionChanged事件,但这在Windows Phone中(直接)是不可能的。如果你想走这条路,你可以看看EventToCommand。本页更详细地解释了这些步骤:

问题不是关于asp.net,而是关于windows phone/xaml真的非常感谢您的回答,但是您知道一种不使用MVVM的方法吗?感谢您的耐心(我是noob),在这种情况下,您可以在事件处理程序中立即执行:NavigationService.Navigate(新Uri(NavigationService.Source+“?Refresh=true”,UriKind.Relative));只需省去ViewModel类,将命令中的代码直接放在处理程序中即可。“刷新当前页面”的确切含义是什么?对于刷新,我的意思正是这个NavigationService.Navigate(新Uri(NavigationService.Source+“?refresh=true”,UriKind.Relative)),但是当我用LispPicker打开页面时,我遇到了一个错误System.NullReferenceException这是代码私有的void lpkVoti_SelectionChanged(对象发送方,SelectionChangedEventArgs e){NavigationService.Navigate(新Uri(NavigationService.Source+“?Refresh=true”,UriKind.Relative));}异常是发生在事件处理程序内部还是之后?如果在内部,哪个对象具有空引用?NavigationService还是NavigationService的Source属性?我刚刚在一个示例应用程序中尝试了这一点,它似乎起了作用。您可以在此处访问xaml:和此处的代码:您可以尝试一下,看看它是否有效,是否有任何不同从你所拥有的中得到什么?