问题描述
你好我使用给予below.I希望列表框选择的项目转到另一个页面XAML文件
<列表框点¯x :NAME =NotchsList11Grid.ColumnSpan =2
保证金=0,0,0,0Grid.Row =3的HorizontalAlignment =左WIDTH =720Grid.RowSpan = 2>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
将; StackPanel的保证金=0,0,0,0Grid.ColumnSpan =3×:名称=ControlsPanel
Grid.Column =0
高度= 215
VerticalAlignment =评出的>
< StackPanel的背景=#eb2427方向=横向>
< TextBlock的Grid.Row =1的FontFamily =宋体字号=34粗细=大胆fontstyle的=正常保证金=10,0,0,0
文本={结合NAME}
/>
< / StackPanel的>
<的ScrollViewer ScrollViewer.HorizontalScrollBarVisibility =可见ScrollViewer.VerticalScrollBarVisibility =已禁用>
<&StackPanel的GT;
< StackPanel的VerticalAlignment =评出的WIDTH =自动>
< ListBox中的ItemsSource ={结合影像}的SelectionChanged =NotchsList11_SelectionChangedWIDTH =自动ScrollViewer.VerticalScrollBarVisibility =已禁用>
< ListBox.ItemsPanel>
< ItemsPanelTemplate>
< StackPanel的方向=横向VerticalAlignment =评出的>
< / StackPanel的>
< / ItemsPanelTemplate>
< /ListBox.ItemsPanel>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
<图像来源={结合}WIDTH =160HEIGHT =120VerticalAlignment =评出的>< /图像>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>
< / StackPanel的>
< / StackPanel的>
< /&的ScrollViewer GT;
< / StackPanel的>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>
在
我的XML文件中给出 <?XML版本=1.0编码=UTF-8>?;
<根和GT;
<类别>
<类别名称=照片>
<文章和GT;
<文章标题=Sherawat的>
< FullContent>
<风格> IMG {填充:2px的;}< /风格与GT;< P> < IMG ALT =Sherawatpimcore_disable_thumbnail =真pimcore_id =5853pimcore_type =资产SRC =HTTP:// feb2013 / bolly --- sherawat-S-即将到来,电影脏政治/ 90_mallika- sherawat_bolly.jpg的风格=宽度:500像素,高度:370px;浮动:左; />&下; / P> < P> Sherawat是所有设置开拍为&放大器; NBSP;< EM>肮脏的政治与LT; / EM>&安培; NBSP;在那里她扮演Bhanwari德维,护士的谋杀案喧腾的最后一年。同时,她会说话的&安培; NBSP;好莱坞,她并没有真正有过任何肉的角色和LT; / P>
< / FullContent>
< thumb_image>
<图像URL =http://sss.com/Photo1.jpeg/>中/>
< / thumb_image>
< /条>
<物品条款ArticleID =2684标题=抢断麦秀>
< FullContent>
< DIV ID =容器类=CF>
<链接rel =stylesheet属性HREF =http://sss.com/imageslider/app/css/demo.css类型=文/ CSS媒体=屏幕/><链接rel =样式表的href =http://sss.com/imageslider/app/css/flexslider.css类型=文/ CSS媒体=屏幕/>< DIV ID =主角色=主><节类=滑块>< DIV CLASS =flexslider>< UL类=幻灯片><李>索南·卡普尔< IMG SRC =HTTP:// SSS。 COM //网站/ var / tmp目录/ thumb_5814_1_01feb2013__appfeed.jpegALT =卡普尔/> /李>< / UL>< /李>
< / DIV>
< / FullContent>
< thumb_image>
<图像URL =HTTP://Photo2.jpeg/>中/>
< / thumb_image>
< /条>
< /文章与GT;
< /分类>
<类别名称=影片>
<文章和GT;
<物品条款ArticleID =415标题=肮脏政治>
< FullContent>
<风格> IMG {填充:2px的;}< /风格与GT;< P> < IMG ALT =Sherawatpimcore_disable_thumbnail =真pimcore_id =5853pimcore_type =资产SRC =http://sss.com/bolly/feb2013/bolly---sherawat-s-upcoming-movie-脏政治/ 90_sherawat_bolly.jpg的风格=宽度:500像素,高度:370px;浮动:左; />&下; / P>
< / FullContent>
< thumb_image>
<图像URL =HTTP://Video1.jpeg/>中/>
< / thumb_image>
< /物品>
<物品条款ArticleID =68称号=数字!>
< FullContent>
< p>触摸,点击,翻页,滑动你不要和放大器;#39;你体验< / p>< BR />< BR />< BR />< BR />< BR />
< / FullContent>
< thumb_image>
<图像URL =HTTP://Video2.jpeg/>中/>
< / thumb_image>
< /条>
< /条>
< /分类>
<类别名称=Bolly>
<文章和GT;
<物品条款ArticleID =415标题=即将上映的电影>
< FullContent>
<风格> IMG {填充:2px的;}< /风格与GT;< P> < IMG ALT =Sherawatpimcore_disable_thumbnail =真pimcore_id =5853pimcore_type =资产SRC =http://sss.com/bolly/feb2013/bolly---sherawat-s-upcoming-movie-脏政治/ 90_sherawat_bolly.jpg的风格=宽度:500像素,高度:370px;浮动:左; />&下; / P>
< / FullContent>
< thumb_image>
<图像URL =http://sss.com/website/var/tmp/thumb_5854_90_mallika-sherawat_thumb_bolly__forfeed.jpeg/>
< / thumb_image>
< /条>
<物品条款ArticleID =436标题=惊喜大礼包>
<说明与GT;
有不仅仅是好的音乐更在三人的近期表现
< /说明>
< FullContent>
<风格> IMG {填充:2px的;}< /风格与GT;< P> < IMG ALT =的Akcentpimcore_disable_thumbnail =真pimcore_id =6110pimcore_type =资产SRC =http://dev2.mercuryminds.com/global/feb2013/surprise-package-at-akcent-concert/ 18_akcent_global.jpg的风格=WIDTH:370px;高度:500像素;浮动:左; />&下; / P>
< / FullContent>
< thumb_image>
<图像URL =http://sss.com/website/var/tmp/thumb_6109_18_akcent_thumb__forfeed.jpeg/>
< / thumb_image>
< /条>
< /条>
< /分类>
< /类别和GT;
< /根>
我MainPage.xaml.cs中的代码
无效ParseXMLFile(字符串dataInXmlFile)
{
试
{
//解析XML文件
的XDocument xmlDoc中= XDocument.Parse(dataInXmlFile);
VAR的查询=从l在xmlDoc.Descendants(类别)
选择新的缺口
{
NAME =(字符串)l.Attribute(名 ).value的,
标题= l.Element(公司章程)的元素(文章)
。选择(S =方式> s.Attribute(题)值)$ b $。 b .ToList(),
图像= l.Element(公司章程)的元素(文章)
.Elements(thumb_image)。元素(图像)
。选择(X =方式> x.Attribute(URL)值).ToList(),
};
的foreach(VAR结果查询)
{
Console.WriteLine(result.name);
的foreach(在result.Titles.Zip VAR细节(result.Images,(ST,SI)=>的String.Format({0} {1},ST,SI)))
{
Console.WriteLine(细节);
}
}
NotchsList11.ItemsSource =查询;
}
赶上(例外五)
{
MessageBox.Show(绑定失败);
}
}
私人无效NotchsList11_SelectionChanged(对象发件人,SelectionChangedEventArgs E)
{
缺口selectedItemData =(发件人为列表框).SelectedValue的缺口;
如果(selectedItemData!= NULL)
{
NavigationService.Navigate(新的URI(的String.Format(/ Test.xaml?参数,selectedItemData.articleid),UriKind.Relative)) ;
}
}
我DetailPage.xaml.cs
保护覆盖无效的OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs E)
{
base.OnNavigatedTo(E);
字符串参数= this.NavigationContext.QueryString [参数];
}
如果我点击任何图像,相关的标题和fullcontent导航到详细信息页面,但fullcontent要显示详细信息页面上的WebView。所以我想这个代码,但selectedItemData越来越空value.i不能导航到其他page.So任何一个可以帮助我在这个问题?
私人无效NotchsList11_SelectionChanged(对象发件人,SelectionChangedEventArgs E)
{
VAR磅=发件人列表框作为;
如果(磅== NULL)回报;
VAR articleSubItem = lb.SelectedItem为NotchSubItem;
如果(articleSubItem == NULL)回报;
App.CurrentArticle = articleSubItem;
NavigationService.Navigate(新的URI(/ Test.xaml将selectedItem =?+ articleSubItem.ArticleId,UriKind.Relative));
NotchsList11.SelectedIndex = -1;
}
要设置的详细信息页
保护覆盖无效的OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs E)
{
字符串的selectedIndex =;
如果(NavigationContext.QueryString.TryGetValue(selectedItem设置,出来的selectedIndex))
{
title.Text = App.CurrentArticle.Titles;
webBrowser.NavigateToString(App.CurrentArticle.FullContent);
}
base.OnNavigatedTo(E);
}
MainPage.xaml中页
< StackPanel的宽度=自动>
< StackPanel的VerticalAlignment =评出的WIDTH =自动>
< ListBox中的ItemsSource ={绑定文章}保证金=5,5,5,0WIDTH =自动ScrollViewer.VerticalScrollBarVisibility =已禁用的SelectionChanged =NotchsList11_SelectionChanged>
< ListBox.ItemsPanel>
< ItemsPanelTemplate>
< StackPanel的方向=横向VerticalAlignment =评出的>
< / StackPanel的>
< / ItemsPanelTemplate>
< /ListBox.ItemsPanel>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
< BORDER BorderBrush =#302c2d背景=#302c2d了borderThickness =5,5,5,0NAME =形象保证金=3,0,3,0>
<图像来源={结合图像}WIDTH =141HEIGHT =95NAME =值拉伸=填充VerticalAlignment =评出的>< /图片>
< /边框>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>
< / StackPanel的>
< StackPanel的方向=横向VerticalAlignment =评出的WIDTH =自动>
< ListBox的X:名称=NotchsList11的ItemsSource ={绑定文章}保证金=5,0,5,0ScrollViewer.VerticalScrollBarVisibility =已禁用的SelectionChanged =NotchsList11_SelectionChanged>
< ListBox.ItemsPanel>
< ItemsPanelTemplate>
< StackPanel的方向=横向>
< / StackPanel的>
< / ItemsPanelTemplate>
< /ListBox.ItemsPanel>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
< BORDER BorderBrush =#302c2d背景=#302c2d了borderThickness =5,5,5,0保证金=3,0,3,0>
< TextBlock的文本={结合标题}WIDTH =141HEIGHT =90填充=3,0,0,30TextWrapping =自动换行>< / TextBlock的>
< /边框>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>
< / StackPanel的>
< / StackPanel的>
MainPage.xaml.cs中
的XDocument xmlDoc中= XDocument.Parse(dataInXmlFile);
VAR的查询=从l在xmlDoc.Descendants(类别)
选择新的缺口
{
NAME =(字符串)l.Attribute(名 ).value的,
标题= l.Element(公司章程)的元素(文章)
。选择(S =方式> s.Attribute(题)值)$ b $。 ; b .ToList(),
文章= l.Element(公司章程)的元素(文章)
。选择(文=>新建NotchSubItem
{
图像= article.Element(thumb_image)。元素(图像)。属性(URL)。价值
=条款ArticleID article.Attribute(条款ArticleID)。价值,
FullContent = article.Element(FullContent)。Value.ToString(),
标题= article.Attribute(题)。价值
})
。了ToList(),
图像= l.Element(公司章程)的元素(文章)。元素(thumb_image)。元素(图像)
。选择( X => 。x.Attribute(URL)值).ToList(),
};
的foreach(VAR结果查询)
{
Console.WriteLine(result.name);
的foreach(在result.Titles.Zip VAR细节(result.Images,(ST,SI)=>的String.Format({0} {1},ST,SI)))
{
Console.WriteLine(细节);
}
}
NotchsList11.ItemsSource =查询;
}
赶上(例外五)
{
MessageBox.Show(绑定失败);
}
Hi am using XAML file given below.I want to Navigate Listbox selected item to another page.
<ListBox x:Name="NotchsList11" Grid.ColumnSpan="2"
Margin="0,0,0,0" Grid.Row="3" HorizontalAlignment="left" Width="720" Grid.RowSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,0" Grid.ColumnSpan="3" x:Name="ControlsPanel"
Grid.Column="0"
Height="215"
VerticalAlignment="Top">
<StackPanel Background="#eb2427" Orientation="Horizontal">
<TextBlock Grid.Row="1" FontFamily="Calibri" FontSize="34" FontWeight="Bold" FontStyle="Normal" Margin="10,0,0,0"
Text="{Binding name}"
/>
</StackPanel>
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<StackPanel>
<StackPanel VerticalAlignment="Top" Width="Auto">
<ListBox ItemsSource="{Binding Images}" SelectionChanged="NotchsList11_SelectionChanged" Width="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Width="160" Height="120" VerticalAlignment="Top"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</StackPanel>
</ScrollViewer>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My xml file given below
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Categories>
<Category name="Photos">
<Articles>
<article title="Sherawat's">
<FullContent>
<style> img {padding:2px;} </style><p> <img alt=" Sherawat" pimcore_disable_thumbnail="true" pimcore_id="5853" pimcore_type="asset" src="http://feb2013/bolly---sherawat-s-upcoming-movie-dirty-politics/90_mallika-sherawat_bolly.jpg" style="width: 500px; height: 370px; float: left;" /></p> <p>Sherawat is all set to begin shooting for <em>Dirty Politics</em> where she plays Bhanwari Devi, a nurse whose murder hit the headlines last year. Meanwhile, she gets talking on Hollywood where she has not really had any meaty roles.</p>
</FullContent>
<thumb_image>
<image url="http://sss.com/Photo1.jpeg"/>"/>
</thumb_image>
</article>
<article articleid="2684" title="Steals the Mai Show">
<FullContent>
<div id="container" class="cf">
<link rel="stylesheet" href="http://sss.com/imageslider/app/css/demo.css" type="text/css" media="screen" /> <link rel="stylesheet" href="http://sss.com/imageslider/app/css/flexslider.css" type="text/css" media="screen" /><div id="main" role="main"> <section class="slider"> <div class="flexslider"> <ul class="slides"><li>Sonam Kapoor<img src="http://sss.com//website/var/tmp/thumb_5814_1_01feb2013__appfeed.jpeg" alt="Kapoor"/>/li> </ul></li>
</div>
</FullContent>
<thumb_image>
<image url="http://Photo2.jpeg"/>"/>
</thumb_image>
</article>
</Articles>
</Category>
<Category name="Videos">
<Articles>
<article articleid="415" title=" Dirty Politics">
<FullContent>
<style> img {padding:2px;} </style><p> <img alt="Sherawat" pimcore_disable_thumbnail="true" pimcore_id="5853" pimcore_type="asset" src="http://sss.com/bolly/feb2013/bolly---sherawat-s-upcoming-movie-dirty-politics/90_sherawat_bolly.jpg" style="width: 500px; height: 370px; float: left;" /></p>
</FullContent>
<thumb_image>
<image url="http://Video1.jpeg"/>"/>
</thumb_image>
</articles>
<article articleid="68" title="Digital!">
<FullContent>
<p> Touch, tap, flip, slide! You don'you experience it.</p> <br/><br/><br/> <br/><br/>
</FullContent>
<thumb_image>
<image url="http://Video2.jpeg"/>"/>
</thumb_image>
</article>
</Article>
</Category>
<Category name="Bolly">
<Articles>
<article articleid="415" title="upcoming movie">
<FullContent>
<style> img {padding:2px;} </style><p> <img alt="Sherawat" pimcore_disable_thumbnail="true" pimcore_id="5853" pimcore_type="asset" src="http://sss.com/bolly/feb2013/bolly---sherawat-s-upcoming-movie-dirty-politics/90_sherawat_bolly.jpg" style="width: 500px; height: 370px; float: left;" /></p>
</FullContent>
<thumb_image>
<image url="http://sss.com/website/var/tmp/thumb_5854_90_mallika-sherawat_thumb_bolly__forfeed.jpeg"/>
</thumb_image>
</articles>
<article articleid="436" title="Surprise Package">
<Description>
There was more than just good music at the trio's recent performance
</Description>
<FullContent>
<style> img {padding:2px;} </style><p> <img alt="Akcent" pimcore_disable_thumbnail="true" pimcore_id="6110" pimcore_type="asset" src="http://dev2.mercuryminds.com/global/feb2013/surprise-package-at-akcent-concert/18_akcent_global.jpg" style="width: 370px; height: 500px; float: left;" /></p>
</FullContent>
<thumb_image>
<image url="http://sss.com/website/var/tmp/thumb_6109_18_akcent_thumb__forfeed.jpeg"/>
</thumb_image>
</article>
</Article>
</Category>
</Categories>
</root>
My MainPage.xaml.cs code
void ParseXMLFile(string dataInXmlFile)
{
try
{
//Parsing XML File
XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
var query = from l in xmlDoc.Descendants("Category")
select new Notch
{
name = (string)l.Attribute("name").Value,
Titles = l.Element("Articles").Elements("article")
.Select(s => s.Attribute("title").Value)
.ToList(),
Images = l.Element("Articles").Elements("article")
.Elements("thumb_image").Elements("image")
.Select(x => x.Attribute("url").Value).ToList(),
};
foreach (var result in query)
{
Console.WriteLine(result.name);
foreach (var detail in result.Titles.Zip(result.Images, (st, si) => string.Format("{0} {1}", st, si)))
{
Console.WriteLine(detail);
}
}
NotchsList11.ItemsSource= query;
}
catch(Exception e)
{
MessageBox.Show("Binding Failed");
}
}
private void NotchsList11_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Notch selectedItemData = (sender as ListBox).SelectedValue as Notch;
if(selectedItemData != null)
{
NavigationService.Navigate(new Uri(string.Format("/Test.xaml?parameter",selectedItemData.articleid), UriKind.Relative));
}
}
My DetailPage.xaml.cs
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string parameter = this.NavigationContext.QueryString["parameter"];
}
If i click any image,related title and fullcontent navigate to details page but fullcontent want to show webview on details page. so I tried this code but selectedItemData getting null value.i cant navigate to other page.So any one can help me to resolve in this problem?
private void NotchsList11_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var lb = sender as ListBox;
if (lb == null) return;
var articleSubItem = lb.SelectedItem as NotchSubItem;
if (articleSubItem == null) return;
App.CurrentArticle = articleSubItem;
NavigationService.Navigate(new Uri("/Test.xaml?selectedItem=" + articleSubItem.ArticleId, UriKind.Relative));
NotchsList11.SelectedIndex = -1;
}
To set details page
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
title.Text = App.CurrentArticle.Titles;
webBrowser.NavigateToString(App.CurrentArticle.FullContent);
}
base.OnNavigatedTo(e);
}
MainPage.xaml page
<StackPanel Width="Auto">
<StackPanel VerticalAlignment="Top" Width="Auto">
<ListBox ItemsSource="{Binding Articles}" Margin="5,5,5,0" Width="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionChanged="NotchsList11_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="#302c2d" Background="#302c2d" BorderThickness="5,5,5,0" Name="image" Margin="3,0,3,0">
<Image Source="{Binding Image}" Width="141" Height="95" Name="value" Stretch="Fill" VerticalAlignment="Top"></Image>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Width="Auto">
<ListBox x:Name="NotchsList11" ItemsSource="{Binding Articles}" Margin="5,0,5,0" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionChanged="NotchsList11_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate >
<Border BorderBrush="#302c2d" Background="#302c2d" BorderThickness="5,5,5,0" Margin="3,0,3,0">
<TextBlock Text="{Binding Titles}" Width="141" Height="90" Padding="3,0,0,30" TextWrapping="Wrap"></TextBlock>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</StackPanel>
MainPage.xaml.cs
XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
var query = from l in xmlDoc.Descendants("Category")
select new Notch
{
name = (string)l.Attribute("name").Value,
Titles = l.Element("Articles").Elements("article")
.Select(s => s.Attribute("title").Value)
.ToList(),
Articles = l.Element("Articles").Elements("article")
.Select(article => new NotchSubItem
{
Image = article.Element("thumb_image").Element("image").Attribute("url").Value,
ArticleId = article.Attribute("articleid").Value,
FullContent = article.Element("FullContent").Value.ToString(),
Titles = article.Attribute("title").Value,
})
.ToList(),
Images = l.Element("Articles").Elements("article").Elements("thumb_image").Elements("image")
.Select(x => x.Attribute("url").Value).ToList(),
};
foreach (var result in query)
{
Console.WriteLine(result.name);
foreach (var detail in result.Titles.Zip(result.Images, (st, si) => string.Format("{0} {1}", st, si)))
{
Console.WriteLine(detail);
}
}
NotchsList11.ItemsSource = query;
}
catch(Exception e)
{
MessageBox.Show("Binding Failed");
}
这篇关于如何从列表框设置页面导航到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!