Wpf 在ControlTemplate中绑定CollectionViewSource
我正在尝试创建一个ControlTemplate,它将2个iQueryTables(和其他一些东西)合并到一个CompositeCollection中 获取CollectionViewSource.Source以正确绑定到模板时遇到问题。似乎不支持参考资料部分中的TemplateBinding。绕过这一限制的最佳方式是什么 代码示例如下: --C# --XAMLWpf 在ControlTemplate中绑定CollectionViewSource,wpf,xaml,Wpf,Xaml,我正在尝试创建一个ControlTemplate,它将2个iQueryTables(和其他一些东西)合并到一个CompositeCollection中 获取CollectionViewSource.Source以正确绑定到模板时遇到问题。似乎不支持参考资料部分中的TemplateBinding。绕过这一限制的最佳方式是什么 代码示例如下: --C# --XAML 对于任何感兴趣的人来说,WPF的未来版本将尝试用一种称为“继承上下文”的东西来解决这个问题。 IQueryable Items1; /
对于任何感兴趣的人来说,WPF的未来版本将尝试用一种称为“继承上下文”的东西来解决这个问题。
IQueryable Items1; // (DependencyProperty)
IQueryable Items2; // (DependencyProperty)
<ControlTemplate TargetType="{x:Type Components:Selector}">
<ControlTemplate.Resources>
<!-- The two bound properties below fail to bind -->
<CollectionViewSource Source="{Binding Items1,RelativeSource={RelativeSource TemplatedParent}}" x:Key="Items1Key" />
<CollectionViewSource Source="{Binding Items2, RelativeSource={RelativeSource TemplatedParent}}" x:Key="Items2Key" />
<CompositeCollection x:Key="collection">
<CollectionContainer Collection="{Binding Source={StaticResource Items1Key}}" />
<CollectionContainer Collection="{Binding Source={StaticResource Items2Key}}" />
</CompositeCollection>
</ControlTemplate.Resources>
<ComboBox ItemsSource="{Binding Source={StaticResource collection}}" />
</ControlTemplate>