我正在使用Visual Studio 2012(c#和XAML)并创buildWindows Phone应用程序
我有我的页面1上的列表视图,当点击即列表视图项目1时单击图像出现。
这也发生在另一个项目,我想要的是,当他们已经点击列表视图中的值时,他们被带到另一个页面,当点击图片出现在文字描述在第一页popup的图片
例如,在列表视图项1中单击时,Jk罗琳的图像出现在右侧,如果用户单击该图像,他们进入第二页(这是工作正常),但是当我点击第一页上的图片我希望文本加载到我在第二页上创build的文本框中,以便用户看到关于该作者的长描述。 (所以我想要显示不同的文本取决于用户select了什么样的listview项目)
以下是我的代码
第一页
public void AuthorList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (AuthorList.SelectedIndex == 1) { BitmapImage Dostoyevsky = new BitmapImage(new Uri("dostoyevsky.jpg",UriKind.Relative)); AuthorImage.Source = Dostoyevsky; AuthordescriptionText.Text = @"Born: 11 November 1821 Died: February 9 1881 of Epilepsy, Emphysema Dostoyesky is one of the greats of Russian literature with novels such as Crime and Punishment, The Idiot Demons and The Brothers Karamazov"; } else if (AuthorList.SelectedIndex == 2) { BitmapImage Tolstoy = new BitmapImage(new Uri("tolstoy.jpg", UriKind.Relative)); AuthorImage.Source = Tolstoy; AuthordescriptionText.Text = @"Born: 9 September 1828 Died: 20 November 1910 (Pneumonia) Tolstoy is usually remembered as the man who created the masterpiece War & Peace which is over 1000 pages, his other works include Anna karanina and his trilogy Childhood, boyhood and youth which is based on his experiences in the Crimean war"; } else if (AuthorList.SelectedIndex == 3) { BitmapImage Turgenev = new BitmapImage(new Uri("turgenev.jpg", UriKind.Relative)); AuthorImage.Source = Turgenev; } } private void GoToAuthorPage(object sender, RoutedEventArgs e) { } public void ImageTapTodifferent(object sender, GestureEventArgs e) { if (AuthorList.SelectedIndex == 1) { } NavigationService.Navigate(new Uri("/AuthorPage.xaml", UriKind.Relative)); } private void UpdateImage(object sender, EventArgs e) { AuthordescriptionText.Opacity = 50; } protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { } } }
第二页
private void BackButton(object sender, RoutedEventArgs e) { NavigationService.GoBack(); } private void OnTapAuthorPage(object sender, System.Windows.Input.GestureEventArgs e) { AuthorDescrptionLong.Text = @" Quote: If you want to be happy, be. } } }
看到你的代码后,我认为你不会去写的方式。 但是你会学习经验。 所以我建议你为你的应用程序使用MVVM模式。 尝试制作一个遵循mvvm模式的示例应用程序,并使用绑定进行播放。
所以基本上试试GalaSoft MVVM Toolkit nuget包并安装它。 之后,你应该创建两个ViewModels(最简单的方法)为你的两个单独的页面说Page1ViewModel和Page2Viewmodel 。
为了简单的用法,在Page2ViewModel中做了一个字符串类型属性,该属性应该绑定到你的第二页“AuthorDescrptionLong.Text”。
现在,您可以使用MessengerClass在Viewmodels之间进行通信。
我在这里提到很多,所以请阅读这些链接以获得指导。 现在是时候学习新的东西:)
我不知道这是你的问题的答案,但如果你正在开发的Windows手机,然后学习我所建议的。 快乐学习:)