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>

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Add

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

to you containers.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.