Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListBox not showing items horizontally after using theme

Tags:

wpf

I am using a listbox as my Menu items holder, by using

            <ListBox.ItemsPanel>

                <ItemsPanelTemplate>

                    <VirtualizingStackPanel Orientation="Horizontal" />

                    <WrapPanel></WrapPanel>

                </ItemsPanelTemplate>

            </ListBox.ItemsPanel>

i can show all my items horizontally in listbox but whenever i use any theme it started showing items vertically (I am using Microsoft's ExpressionLight.xaml in my project's Application.xaml)

Any solution, even if how to stop my listbox (only this one) using theme.

Regards,

like image 920
Adnan Badar Avatar asked Mar 02 '26 00:03

Adnan Badar


2 Answers

We had the same problem with ExpressionDark and discovered it was a problem in the Style.

To fix simply modify the ListBox ControlTemplate (Line 710 in ExpressionDark.xaml for us):

<ControlTemplate TargetType="{x:Type ListBox}">
    <Grid>
        <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" Background="{DynamicResource ControlBackgroundBrush}" />
        <ScrollViewer Margin="1" Style="{DynamicResource NuclearScrollViewer}" Focusable="false" Background="{x:Null}">
            <StackPanel Margin="1,1,1,1" IsItemsHost="true" />
        </ScrollViewer>
    </Grid>
    ...

Change the StackPanel to an ItemsPresenter:

<ItemsPresenter Margin="1,1,1,1"/>

And you should be good to go.

like image 151
Rodney Thomson Avatar answered Mar 05 '26 07:03

Rodney Thomson


I'd guess the theme has a default setting for orientation which overwrites your settings?

like image 40
dain Avatar answered Mar 05 '26 08:03

dain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!