我有一个ListView
控件,用于显示XML文件中的数据。但是ListView
有GridView
个孩子,有两列 - 图标和标题。我的想法是当我点击元素以仅从标题列获取值时。相反,我获得了整个XML节点。
这是一个理论问题,但如果你需要代码,我会提供它:)
谢谢
更新
XML文件:
<list>
<item>
<title>demo</title>
<icon>icon.png</icon>
</item>
<item>
<title>demo2</title>
<icon>icon2.png</icon>
</item>
</list>
XAML:
<Page.Resources>
<XmlDataProvider x:Key="feed"
Source="http://feedurl/sites.xml"
XPath="list/item" />
<DataTemplate x:Key="itemIcons">
<Grid x:Name="ImageGrid">
<Image Source="{Binding XPath=icon}" Width="40" Height="40"></Image>
</Grid>
</DataTemplate>
</Page.Resources>
更多XAML:
<ListView Name="myList" ItemContainerStyle="{StaticResource MyContainer}"
SelectionChanged="clicked" FontSize="16" HorizontalAlignment="Left"
Height="auto" ScrollViewer.VerticalScrollBarVisibility="auto" VerticalAlignment="Stretch" Width="240"
BorderBrush="Transparent" BorderThickness="0"
ItemsSource="{Binding Source={StaticResource feed}}"
SelectionMode="Single" Margin="1,36,1,1">
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style>
<Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridView.Columns>
<GridViewColumn x:Name="showIcon" CellTemplate="{StaticResource itemIcons}"/>
<GridViewColumn x:Name="showSites" DisplayMemberBinding="{Binding XPath=title}" Header="some header"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
C#:
private void clicked(object sender, SelectionChangedEventArgs e)
{
var title= this.myList.SelectedValue.ToString();
//MessageBox.Show(title);
}
当我点击我的ListView
项目时,我得到标题和图标节点连接在一起,例如“demoicon.png”,我只想要“标题”值:)
提前感谢;)