我想知道如何使用
刷新当前页面 heNavigationService.Navigate(new Uri(NavigationService.Source + "?Refresh=true", UriKind.Relative));
我在ListPicker中选择一个元素。
答案 0 :(得分:1)
我想你正在使用MVVM Light for Windows Phone。在这种情况下,您应该在页面中捕获事件,然后在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直接绑定到SelectionChanged事件,但这在Windows Phone中不是(直接)可能的。如果你想走这条路,你可以看看EventToCommand。此页面更详细地解释了这些步骤:http://www.geekchamp.com/articles/how-to-bind-a-windows-phone-control-event-to-a-command-using-mvvm-light
答案 1 :(得分:-1)
将您的autopostback设置为true,示例:
<asp:DropDownList OnSelectedIndexChanged="dropDown_indexChange" ID="DropDownList1" runat="server" AutoPostBack="True">