【发布时间】:2014-01-19 01:11:19
【问题描述】:
我有一个列表框,其中包含我正在尝试开发的控件选择器。基本上,数据源是 XML,我想读取当前上下文来决定显示哪个元素控件。
为此,我想使用当前项目的上下文获取 XmlDataProvider,并评估该 XML。在 XAML 中,我将编写 {Binding Path=@label} 以从 curretn XML 元素中检索标签属性。从后面的代码中,我什至无法确定从何处获取此 XML,因为它是由列表控件传递给类的,但据我所知,它不是可访问的属性。
无论如何获得@label 是不够的;我想要 ControlChooser 类中的 XmlElement 对象,在下面实例化。
<ListBox
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding XPath=*[not(self::units)]}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<W3V:ControlChooser/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<!-- Force the items to fill all available space. -->
<Style TargetType="ListBoxItem">
<Setter
Property="VerticalContentAlignment"
Value="Stretch"
/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
或者,如果您可以建议另一种方法来完成这项工作(切换显示的控件)......
【问题讨论】: