繁体   English   中英

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

[英]How to refresh the current page after selecting an item in ListPicker

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

heNavigationService.Navigate(new Uri(NavigationService.Source + "?Refresh=true", UriKind.Relative));

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

我想您正在为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;}

}

Xaml

<ListBox SelectionChanged="Listbox_SelectionChanged" />

从理论上讲,您不必在代码背后进行此操作,您可以将ViewModel中的Command直接绑定到SelectionChanged事件,但这在Windows Phone中是(直接)不可能的。 如果您想走这条路线,可以看看EventToCommand。 此页面更详细地说明了步骤: http : //www.geekchamp.com/articles/how-to-bind-a-windows-phone-control-event-to-a-command-using-mvvm-light

将自动回传设置为true,示例:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM