[英]How to refresh the current page after selecting an item in ListPicker
I'd like to know how to refresh the current page with 我想知道如何刷新当前页面
heNavigationService.Navigate(new Uri(NavigationService.Source + "?Refresh=true", UriKind.Relative));
after i pick an element in the ListPicker. 我在ListPicker中选择一个元素后。
I suppose you are using MVVM Light for Windows Phone. 我想您正在为Windows Phone使用MVVM Light。 In that case, you should catch the event in your page and then trigger a command on your ViewModel.
在这种情况下,您应该在页面中捕获事件,然后在ViewModel上触发命令。
Example: 例:
Code-behind of the page 页面的代码隐藏
private void Listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ViewModelClass vm = this.DataContext as ViewMoedlClass;
if (vm != null)
{
vm.RefreshCommand.Execute();
}
}
ViewModel 视图模型
class ViewModelClass
{
public ViewModelClass
{
this.RefreshCommand = new RelayCommand(() =>
{
NavigationService.Navigate(new Uri(NavigationService.Source + "?Refresh=true", UriKind.Relative));
}
}
public RelayCommand RefreshCommand { get; set;}
}
Xaml Xaml
<ListBox SelectionChanged="Listbox_SelectionChanged" />
In theory you shouldn't have to do this in your code-behind and you would bind your Command from the ViewModel directly to the SelectionChanged-event, but this is not (directly) possible in Windows Phone. 从理论上讲,您不必在代码背后进行此操作,您可以将ViewModel中的Command直接绑定到SelectionChanged事件,但这在Windows Phone中是(直接)不可能的。 If you want to go this route you can take a look at EventToCommand.
如果您想走这条路线,可以看看EventToCommand。 This page explains the steps in more detail: http://www.geekchamp.com/articles/how-to-bind-a-windows-phone-control-event-to-a-command-using-mvvm-light
此页面更详细地说明了步骤: 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.