大家好:
最近在做一个自定义控件,由于对WPF还不是特别熟悉,需要向大家讨教一些问题。
首先,我的xml文件内容如下:
<catalog>
<group name="test group">
<lyr name="firstLayer">
<other att1="" attr2=""></other>
</lyr>
<lyr>...</lyr>
</group>
</catalog>
下面是我的HierarchicalDataTemplate的内容:
<HierarchicalDataTemplate DataType="catalog" ItemsSource="{Binding XPath=*}" >
<TextBlock Text="root"></TextBlock>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="group" ItemsSource="{Binding XPath=*}">
<StackPanel Orientation="Horizontal">
<CheckBox IsThreeState="True" Margin="6"></CheckBox>
<TextBlock Text="{Binding XPath=@name}" Margin="4,4"></TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="layer" ItemsSource="{Binding XPath=*}">
<StackPanel Orientation="Horizontal">
<local:MyUserControl Layer="{Binding XPath=other}" >
</local:MyUserControl>
</StackPanel>
</HierarchicalDataTemplate>
其中MyUserControl是我自定义的控件,其中属性Layer是一个依赖项属性,需要将xml文件中的other传递进去。但是在这里遇到一个问题,我的Layer属性应该定义为什么数据类型,我试过XmlElement,BindingBase,string,但是取得都是null。是不是我的绑定有问题