【问题标题】:Adding Items Using DataBinding from TreeView to ListBox WPF使用 DataBinding 从 TreeView 添加项目到 ListBox WPF
【发布时间】:2008-09-10 15:37:24
【问题描述】:

我想使用DataBindingTreeView 中的选定项目添加到ListBox 控件(如果它可以与DataBinding 一起使用)。

<TreeView HorizontalAlignment="Left" 
          Margin="30,32,0,83" 
          Name="treeView1" 
          Width="133" >

</TreeView>
<ListBox VerticalAlignment="Top" 
         Margin="208,36,93,0" 
         Name="listBox1" 
         Height="196" >       
</ListBox>

TreeView 由页面后面的代码填充一些虚拟数据。

【问题讨论】:

    标签: wpf data-binding listbox treeview


    【解决方案1】:

    您可以使用 ElementName 绑定到元素,因此如果您想将选定的树项绑定到 ListBox 的 ItemsSource:

    ItemsSource="{Binding SelectedItem, ElementName=treeView1}"
    

    【讨论】:

      【解决方案2】:

      我很确定这是可能的,因为 WPF 在数据绑定方面非常灵活,但我还没有完成那个特定的场景。

      最近我一直在关注 MSDN 博客中的 WPF Databinding FAQ,它提供了许多可能会有所帮助的见解。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        相关资源
        最近更新 更多