【问题标题】:Nested ListBox: is it possible to recover the parent ListBox item when a child ListBox item is selected?嵌套列表框:选择子列表框项目时是否可以恢复父列表框项目?
【发布时间】:2012-02-13 16:23:53
【问题描述】:

我有一个嵌套的 ListBoxes,例如可以包含 PicturesListBox 和 audioRecordListBox 的 warningListBox 项。 当我选择子ListBox的一个元素(例如pictureListBox的项)时,我不仅需要恢复选择的图片项,还需要恢复父警告ListBox的项(warningListBox的项)。 在 mediaListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 我可以恢复选中的子项

((System.Windows.Controls.ListBox)sender).SelectedItem

但是我怎样才能恢复父警告列表框的项目??

我必须在每个 ListBox 子元素中添加一个带有父项 id 的附加字段吗? ...还是有更好的解决方案,例如在发送者中导航或使用 SelectionChanged 事件的 eventArgs?

等待一些建议...

恩佐·康蒂尼

【问题讨论】:

    标签: windows-phone-7 listbox nested


    【解决方案1】:

    使数据结构类似于您拥有的 UI 可能是最简单的。所以也让数据结构嵌套。

    要启用跟踪父项,请将 Parent 属性添加到子项。

    这样你可以像这样得到父项:

    var parent = ((MySubitem)((System.Windows.Controls.ListBox)sender).SelectedItem).Parent;
    

    您可能会发现维护这种结构比尝试跟踪 UI 控件更容易。

    【讨论】:

    • 谢谢尔诺。我已经有一个反映嵌套结构的数据源: public class AttachmentsPivotDataSource { private SignallingList _warningSignallingList; public SignallingList WarningSignallingList { //per PivotItem Name="WarningsPivotItem" get { return _warningSignallingList; } 设置 { _warningSignallingList = 值; OnPropertyChanged("警告信号列表"); } } ...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    相关资源
    最近更新 更多