如何从ListBox中获取Header Information? [英] How to get Header In formation form ListBox?

查看:97
本文介绍了如何从ListBox中获取Header Information?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击listBox项目时,我在selectionChanged事件中得到一个SubItem。我也需要获得标题。我怎么能实现它?

When I tap on listBox item i get a SubItem in "selectionChanged" event. I need to get Title as well. How i can achieve it?

public class Data
   {
       public string Title { get; set; }
       public List<SubItem> SubItems { get; set; }
       public Data()
       {
           SubItems = new List<SubItem>();





}

}



}
}

<phone:LongListSelector ItemsSource="{Binding DataCollection}" Grid.Row="0">
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Title}" Padding="5" />
                            <TextBlock Text="{Binding ImageSource}" Padding="5"/>
                        </StackPanel>
                        <ListBox ItemsSource="{Binding SubItems}" SelectionChanged="ListBox_SelectionChanged">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Vertical"/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding SubItemTitle}" Margin="0,0,12,0" Padding="10" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>
                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector>

推荐答案

请尝试以下方法:

Try the following:
<TextBlock Text="{Binding SubItemTitle}" Margin="0,0,12,0" Padding="10" 

Tag="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type LongListSelector}}, Path=ItemsSource.Title}"/>



目前我还没有可用的winphone环境,因此请测试AncestorType和Path的值。

这应该通过TextBlock的Tag属性使标题可用,因此可以从事件中访问。


I don't have a winphone environment available at this moment, so please test the values for AncestorType and Path.
This should make the title availble through the Tag property of the TextBlock, and therefore accessible from the event.


这篇关于如何从ListBox中获取Header Information?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆