Связывание CollectionViewSource в ControlTemplate - PullRequest
1 голос
/ 09 марта 2010

Я пытаюсь создать ControlTemplate, который объединит 2 IQueryables (и некоторые другие вещи) в CompositeCollection.

У меня проблемы с получением CollectionViewSource.Source для правильной привязки к шаблону. Похоже, 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...