[英]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.