2008-10-29 5 views
1

각 ListBoxItem에 이미지와 텍스트를 표시하기 위해 Windows ListBox를 재정의했습니다. 그러나 실제 ListBox의 DisplayMemberPath에 액세스하여 표시하려는 텍스트의 내용을 필터링해야합니다. 작동시키지 못한다. ListBoxItem의 내용에 바인딩하려고 할 때 ListBox에서 DisplayMemberPath에 어떻게 액세스합니까?

<Setter Property="ItemContainerStyle"> 
     <Setter.Value> 
      <!-- Simple ListBoxItem - This is used for each Item in a ListBox. The item's content is placed in the ContentPresenter --> 
      <Style TargetType="{x:Type ListBoxItem}"> 
       <Setter Property="SnapsToDevicePixels" Value="true"/> 
       <Setter Property="OverridesDefaultStyle" Value="true"/> 
       <Setter Property="VerticalContentAlignment" Value="Center"/> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
          <Grid SnapsToDevicePixels="true"> 
           <Border x:Name="Border"> 
            <Grid Height="40"> 
             <Grid.ColumnDefinitions> 
              <ColumnDefinition Width="Auto"/> 
              <ColumnDefinition Width="*"/> 
             </Grid.ColumnDefinitions> 
             <Image 
              Source="{Binding Path=ThumbnailImage}" 
              Height="30" 
              Width="30" 
              Grid.Column="0"/> 

             <Label 
              x:Name="Text" 
              Content="{TemplateBinding DisplayMemberPath}" 
              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
              VerticalContentAlignment="Center" 
              HorizontalAlignment="Stretch" 
              Grid.Column="1" 
              Height="40"/> 
            </Grid> 
           </Border> 
          </Grid> 
          <ControlTemplate.Triggers> 
           <Trigger Property="IsSelected" Value="true"> 
            <Setter Property="FontWeight" Value="Bold" TargetName="Text"/> 
            <Setter Property="Foreground" Value="White" TargetName="Text"/> 
            <Setter Property="Background" Value="Blue" TargetName="Border"/> 
           </Trigger> 
          </ControlTemplate.Triggers> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </Setter.Value> 
    </Setter> 

내가 내 스타일을 위해 사용하고있는 코드이며,이 내가 작업을 얻을 수없는 라인이었다

내용 = "{TemplateBinding DisplayMemberPath}"

그것은과 불평 : 를 'ListBoxItem'유형의 정적 멤버 'DisplayMemberPathProperty'를 찾을 수 없습니다.

누구나 올바른 방향으로 나를 가리킬 수 있습니까?

답변

0

괜찮 았어, 이제 ListBox에서 값을 얻었고, 필요한 것은 itemsSource의 dataObject에서 필요한 속성으로 변환하는 것뿐입니다.

Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=DisplayMemberPath}" 
: 경우의 사람이 코드를 알고 싶어 그냥에서

관련 문제