jo.hwg
jo.hwg

Reputation: 7

Split RadioButtons/Checkbox into 2 columns

I have a lot of RadioButtons and Checkboxes and I basically want to split them in a second Column, to make it look more user friendly. I found some examples but not really for WPF.

Picture of Buttons

Picture of Buttons

and this is my XAML:

<Grid>
    <ItemsControl ItemsSource="{Binding AuswahlOptionenViewModelCollection}"  Margin="115,50,0,0">
        <ItemsControl.ItemTemplate>
            <DataTemplate DataType="antwortmoeglichkeiten:OptionViewModel">
                <Viewbox Height="25" HorizontalAlignment="Left" VerticalAlignment="Top">
                    <CheckBox Style="{DynamicResource MaterialDesignUserForegroundCheckBox}"
                              CommandParameter="{Binding}"
                              Command="{Binding SelectedOptionViewModelCommand}"
                              IsChecked="{Binding Selected}"
                              Content="{Binding Value}"/>
                </Viewbox>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

Upvotes: 0

Views: 80

Answers (1)

ASh
ASh

Reputation: 35680

You can change ItemsPanel and use UniformGrid with 2 columns:

<ItemsControl ...>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
             <UniformGrid Columns="2"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        ...
    </ItemsControl.ItemTemplate>
</ItemsControl>

Upvotes: 2

Related Questions