0

I am trying to display buttons dynamically on the screen in a wrap panel so that they are laid our nicely without any scrollbars. I have the markup as below, but the scrollbars appear for some reason. how do we make the scrollbar not appear and the buttons laid out without any scrollbars.

<ListBox x:Name="ItemsListBox"  >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <ToggleButton Content="{Binding Name}" Click="Click" MinWidth="120" MinHeight="70" FontWeight="Bold" FontSize="18"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel></WrapPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
TrustyCoder
  • 4,749
  • 10
  • 66
  • 119

3 Answers3

2

What control is your ListBox inside? Most often the problem you descrive is caused by the parent control allowing the ListBox to grow.

You can prove whether this is the problem by setting an explicit Width="200" on your ListBox and testing what happens. If it wraps, then the problem is the ListBox's parent.

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
0

Add

ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"

to you containers.

Wolfgang Ziegler
  • 1,675
  • 11
  • 23
0

This does it what I was trying to achieve.

<ItemsControl x:Name="ListBox" Grid.Row="5"  Grid.ColumnSpan="2">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Vertical"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <ToggleButton Content="{Binding Name}" MinWidth="120" MinHeight="50" FontWeight="Bold" FontSize="16" Margin="5"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
TrustyCoder
  • 4,749
  • 10
  • 66
  • 119