【发布时间】:2010-09-19 19:04:07
【问题描述】:
我已经覆盖了 Windows ListBox,以便在每个 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>
这是我用于我的风格的代码,这是我无法工作的行:
Content="{TemplateBinding DisplayMemberPath}"
它抱怨: 在类型“ListBoxItem”上找不到静态成员“DisplayMemberPathProperty”
谁能指出我正确的方向?
【问题讨论】: