我正在尝试创建控件,该控件将显示ItemsSource
并显示包含在esInnerTemplate
中的所有项目。CheckBox
该控件有 2 个依赖属性:
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(CheckBoxWrapperList), null);
public static readonly DependencyProperty InnerTemplateProperty = DependencyProperty.Register("InnerTemplate", typeof(DataTemplate), typeof(CheckBoxWrapperList), null);
这是模板:
<ControlTemplate TargetType="local:CheckBoxWrapperList">
<Grid>
<Grid.Resources>
<DataTemplate x:Key="wrapper">
<CheckBox>
<ContentPresenter ContentTemplate="{TemplateBinding InnerTemplate}" Content="{Binding}" />
</CheckBox>
</DataTemplate>
</Grid.Resources>
<ItemsControl ItemTemplate="{StaticResource wrapper}" ItemsSource="{TemplateBinding ItemsSource}" />
</Grid>
</ControlTemplate>
但是,这种方法行不通。使用中
的绑定不起作用。
但是,当我不使用模板绑定并将模板作为静态资源引用时,它会按预期工作。ControlPresenter.ContentTemplate
TemplateBinding
- 为什么我不能在 datatemplate 的内容展示器中使用模板绑定?
- 我在这里想念什么?需要什么特殊标记吗?
- 有没有办法实现预期的行为?
提前致谢。