如何创建一个下拉树视图的 silverlight 组合框?
我正在尝试创建一个用户控件,它是一个组合框,打开时会显示层次结构数据的树视图。
我创建了用户控件并将 Popup 中模板的一部分替换为:
<ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
<sdk:TreeView x:Name="Tree">
</sdk:TreeView>
</ScrollViewer>
但是,我不确定如何启用对此的绑定。树视图需要绑定到与组合框不同的数据上下文。我尝试在用户控件上实现 DependencyProperty ,这将允许我设置数据上下文,但我绝对不会以正确的方式进行操作。此时,我得到的只是一个空的树视图。
对此的任何帮助将不胜感激。
PS 一个额外的警告是我需要像这样模板化树视图:
<sdk:TreeView x:Name="Tree">
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding ChildUnits}">
<StackPanel Orientation="Vertical" Width="200">
<TextBlock x:Name="name" TextWrapping="Wrap" Text="{Binding Name}" FontWeight="Bold" />
<TextBlock x:Name="type" Text="{Binding Id}" FontStyle="Italic" FontSize="10" Foreground="Gray" />
</StackPanel>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
I'm trying to create a user control that is a combobox that, when opened, presents a treeview of heirarchal data.
I created the user control and replaced a portion of the template in Popup with:
<ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
<sdk:TreeView x:Name="Tree">
</sdk:TreeView>
</ScrollViewer>
However, I'm not sure how to enable binding on this. The treeview needs to be bound to a different datacontext than the combobox. I tried implementing a DependencyProperty on the user control that would allow me to set the datacontext, but I'm definitely not going about it the right way. At this point, all I get is an empty treeview.
Any help on this would be greatly appreciated.
P.S. One additional caveat is that I need to template the treeview like so:
<sdk:TreeView x:Name="Tree">
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding ChildUnits}">
<StackPanel Orientation="Vertical" Width="200">
<TextBlock x:Name="name" TextWrapping="Wrap" Text="{Binding Name}" FontWeight="Bold" />
<TextBlock x:Name="type" Text="{Binding Id}" FontStyle="Italic" FontSize="10" Foreground="Gray" />
</StackPanel>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论