Posted 6 months ago by BenjaminLopVic - France
Version: 24.1.1
Avatar

Hello,

I'm using a horizontal ListBox to display an Enum, but I needed to hide some values similar to the EnumEditBox. To achieve this, I set a Style on the ListBoxItem to hide items when the EditorBrowsable attribute is set to "Never":

<shared:HorizontalListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}" >
        <Style.Triggers>
            <DataTrigger Binding="{Binding Converter={StaticResource BrowsableToBool}}" Value="False">
                <Setter Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</shared:HorizontalListBox.ItemContainerStyle>

This works fine except that the style no longer resembles the default one. I tried using "BasedOn" like this:

BasedOn="{StaticResource {x:Static themes:SharedResourceKeys.ListBoxItemStyleKey}}"

But I haven't found any style like "HorizontalListBoxItemStyle". With "ListBoxItemStyle", it's better but not perfect; the selected item is gray when the control is not focused instead of blue.

Where can I find the base style for items of a HorizontalListBox ? 

Thanks,

Benjamin.

Comments (2)

Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

We don't have a public key at the moment for that Style.  We will add "{StaticResource {x:Static themes:SharedResourceKeys.HorizontalListBoxItemStyleKey}}" for the next maintenance release.

That being said, you can easily filter down the values you pass to the ItemsSource manually, or could use a CollectionView to do so.  That kind of concept would work with the current version.


Actipro Software Support

Posted 6 months ago by BenjaminLopVic - France
Avatar

Hello,

For more context, I'm using this HorizontalListBox inside a PropertyGrid.

I've already attempted to manually provide only the items I wanted in the itemsSource using an ObjectDataProvider, which I believe is very similar to the solution you suggested. It sort of worked; I have only the enum values that I wanted displayed. However, if my bound value is a value that is not displayed, the listBox won't get updated, and the selected value remains the old one. This is why I opted for the style approach. The listBox contains all values, so the selected value is always correct even if it's not displayed.

Thanks.

Benjamin.

The latest build of this product (v24.1.3) was released 29 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.