I have overridden the windows ListBox in order to display an image and a piece of text in each ListBoxItem, but I need to filter the contents of the text displayed I was hoping to do this by accessing the DisplayMemberPath of the actual ListBox however I can’t get it working.
<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>
This is the code I am using for my style and this was the line I can’t get working:
Content='{TemplateBinding DisplayMemberPath}’
It complains with: Cannot find the static member ‘DisplayMemberPathProperty’ on the type ‘ListBoxItem’
Can anyone point me in the right direction?
Its ok, I have got the value from the ListBox now, all i need to do is convert it to take the property i need from the dataobject in the itemssource.
Just in case anyone wanted to know the code: