C# 将文本从第1页更改为第2页的Listview项
我正在使用Visual Studio 2012(c#和XAML)创建一个Windows phone应用程序 我的第1页上有一个listview,当单击时,即listview项目1,当单击时,会出现一个图像 这也发生在另一个项目上,我想要的是,当他们单击listview中的值时,当他们单击出现的图片时,他们将被带到另一个页面,其中文本描述在第一个页面中弹出的图片 例如,在listview项目1中,当单击时,Jk Rowling的图像会显示在右侧,如果用户单击该图像,他们会转到第二页(这很正常)但是当我点击第一页上的图片时,我希望文本加载到我在第二页上创建的文本框中,以便用户看到关于作者的详细描述。(因此,我希望根据用户选择的listview项目显示不同的文本) 下面是我的代码 首页C# 将文本从第1页更改为第2页的Listview项,c#,windows,windows-phone-7,C#,Windows,Windows Phone 7,我正在使用Visual Studio 2012(c#和XAML)创建一个Windows phone应用程序 我的第1页上有一个listview,当单击时,即listview项目1,当单击时,会出现一个图像 这也发生在另一个项目上,我想要的是,当他们单击listview中的值时,当他们单击出现的图片时,他们将被带到另一个页面,其中文本描述在第一个页面中弹出的图片 例如,在listview项目1中,当单击时,Jk Rowling的图像会显示在右侧,如果用户单击该图像,他们会转到第二页(这很正常)但是
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软件包并安装它。之后,您应该为两个单独的页面创建两个视图模型(最简单的方法),例如Page1ViewModel
和Page2Viewmodel
为了便于使用,在Page2ViewModel
中创建了一个字符串类型属性,该属性应绑定到第二页“AuthorDescrptionLong.Text”
现在,您可以使用Messenger类在Viewmodels之间进行通信
我在这里提到了很多。所以请阅读这些链接以获得指导。是时候学点新东西了:)