代码之家  ›  专栏  ›  技术社区  ›  vanja.

在ControlTemplate中绑定CollectionViewSource

  •  1
  • vanja.  · 技术社区  · 16 年前

    我正在尝试创建一个ControlTemplate,它将2个IQueryables(以及其他一些东西)合并到一个CompositeCollection中。

    我在获取CollectionViewSource时遇到问题。源代码以正确绑定到模板。似乎不支持参考资料部分中的TemplateBinding。绕过这个限制的最佳方式是什么?

    代码示例如下:

    --C#

    IQueryable Items1; // (DependencyProperty)
    IQueryable Items2; // (DependencyProperty)
    

    --XAML

      <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>
    
    0 回复  |  直到 16 年前
    推荐文章