开发者

Binding a CollectionViewSource in a ControlTemplate

开发者 https://www.devze.com 2022-12-22 20:11 出处:网络
I am trying to create a ControlTemplate which will merge 2 IQueryables (and some other things) into a CompositeCollection.

I am trying to create a ControlTemplate which will merge 2 IQueryables (and some other things) into a CompositeCollection.

I am having issues getting the CollectionViewSource.Source to bind correctly to the template. It looks like TemplateBinding in the Resources section is not supported. What is the best way to get around this limitation?

Code sample is below:

-- 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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号