2016-04-15 12 views
0

ItemsControlのItemsSourceがバインドされているリストのオブジェクトにIndexプロパティを作成しましたが、コンバーターにブレークポイントを設定すると、そのバインディングの値はDependancyProperty.UnsetValueになります。 ContentPresenterのデータコンテキストはそのオブジェクトです。オブジェクトにプロパティがありますが、なぜIndexプロパティが表示されませんか?ItemsControl内でバインディングが失敗する理由

<ItemsControl ItemsSource="{Binding Charts}" x:Name="ItemsControl"> 
    <ItemsControl.ItemTemplate> 
     <ItemContainerTemplate > 
      <ContentPresenter Content="{Binding}"> 
       <ContentPresenter.Visibility> 
        <MultiBinding Converter="{StaticResource Converter}"> 
         <Binding Path="Index"/> 
         <Binding Path="WhichAreVisible" /> 
        </MultiBinding> 
       </ContentPresenter.Visibility> 
      </ContentPresenter> 
     </ItemContainerTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

バインドされたオブジェクトのコードを渡せますか? –

答えて

2

ItemTemplateは間違った場所です。それはItemsControlのアイテムの内容を、他のいくつかの子コンテナコントロール(子供1つにつき1個)内に表示するために使用されるDataTemplateまたはItemContainerTemplateになります。他のコンテナコントロールは、その中のコンテンツだけでなく、非表示にしたいものです。もちろん、パディングやマージンを持たない自動サイズの場合、コンテンツが崩壊するとスペースを取らず、残っているものは数えています。

お試しください。 ItemContainerStyleは、実際の子アイテムのスタイルを制御します。 ListBoxでは、ListBoxItemタイプに適用されます。 ItemsControlでは、子はContentPresenterです。すでにItemContainerStyleがある場合は、このトリガーを追加してください。

<ItemsControl.ItemContainerStyle> 
    <Style TargetType="ContentPresenter"> 
     <Setter Property="Visibility"> 
      <Setter.Value> 
       <MultiBinding Converter="{StaticResource Converter}"> 
        <Binding Path="Index"/> 
        <Binding Path="WhichAreVisible" /> 
       </MultiBinding> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</ItemsControl.ItemContainerStyle> 
+0

素晴らしい、それはまさに私が必要としていたものです。ありがとう – kleineg

+0

@kleineg喜んで助けてください。ところで、私は間違ったことが一つあります: 'TargetType'は' ContentControl'ではなく 'ContentPresenter'でなければなりません。 –

関連する問題