views:

7

answers:

1

I have a list box in expander:

<ListBox ItemsSource="{Binding MySource">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <RadioButton Content="{Binding MyContent}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

I wrap the radio button with horizontal orientation stackpanel. I want the overflow radio buttons move down like right image shown below (no horizontal scrollbar). Now, mine is like the left one.

Stackpanel Orientation="Horizontal"

+1  A: 

You need to use a WrapPanel, not a StackPanel. In WPF it's built into the main assemblies but in Silverlight you'll need to get the Silverlight Toolkit.

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding MySource">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <RadioButton Content="{Binding MyContent}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <t:WrapPanel />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>
Josh Einstein
ScrollViewer.HorizontalScrollBarVisibilityProperty should be ScrollViewer.HorizontalScrollBarVisibility. The rest is perfect! Thanks, Josh!
Jeaffrey Gilbert
That's what I get for being lazy and copying and pasting the name. :) Thanks for the heads up.
Josh Einstein