我的WP8.1应用程序获得了一个problam。我有一个listView,当我点击item时,它会让我进入一个带有détails的新页面但是当我回到我的listView时,我可以重新选择相同的项目,但它不会让我到处都是。
这是我在MainPage.xaml.cs中的listView SelectionChanged Handler。
private void lvNom_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Person personneSelect = (Person)lvNom.SelectedItem;
Frame.Navigate(typeof(DetailPersonne), personneSelect);
}
以下是我需要在DetailPersonne.xaml.cs
中显示的页面背后的代码 public sealed partial class DetailPersonne : Page
{
public Person person;
public DetailPersonne()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
person = e.Parameter as Person;
if(string.IsNullOrEmpty(person.Nom) == true){
tbNom.Text = "Non renseigné.";
}
else{
tbNom.Text = person.Nom;
}
if (string.IsNullOrEmpty(person.Prenom) == true)
{
tbPrenom.Text = "Non renseigné.";
}
else{
tbPrenom.Text = person.Prenom;
}
我所做的唯一导航更改是处理App.xaml.cs中的硬件后退按钮
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if(rootFrame != null && rootFrame.CanGoBack)
{
e.Handled = true;
rootFrame.GoBack();
}
}
所以,如果有人得到了修复,那就太好了!提前致谢 ! :)
答案 0 :(得分:0)
尝试重置所选项目时SelectionChanged
没有触发,因为当你导航回来时,选择没有改变。
private void lvNom_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(lvNom.SelectedItem != null)
{
Person personneSelect = (Person)lvNom.SelectedItem;
lvNom.SelectedItem = null;
Frame.Navigate(typeof(DetailPersonne), personneSelect);
}
}