Search code examples
c#wpfcheckboxscrollviewer

I want to make an array of checkbox in scrollviewer control using WPF


I have a list of strings and I want to convert it to checkboxes control in scrollviewer control. How can I do this? Any ideas? The list consists of courses and I want to make it as checkboxes so student can choose some of them.


Solution

  • XAML Part :

       <ScrollViewer>
            <ListBox ItemsSource="{Binding .}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding Path=.}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>
    

    Code-behind part :

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = new string[] {"course1", "course2"};
        }
    }