lundi 12 novembre 2018

how use Multi Checkbox with binding - wpf

I would like assign action to each of my checkboxes, but i don't know how because i use binding.

below is XAML.cs

public MainWindow()
    {
        InitializeComponent();

        Collection1 = new string[] { "Female", "Male", "Animal", "Safe", "Soft", "Hard", "Space", "Landscape", "Outside", "Inside", "City", "France", "Flower", "Sunset", "Sky", "Fireworks", "Spring", "Winter", "Summer", "Fall", "Christmas", "Halloween", "Ghost", "Demon", "Angel", "Watermelon", "Storm", "Waterfall", "Night", "Sun","Moon", "Food", "Cheese", "Kancolle", "IT", "UFO", "Travel", "Sport", "Nightmare"};

        Collection2 = new string[] { "website1", "website2", "website3", "website4", "website5","website6", "website7", "website8", "website9", "website10", "website11", "website12", "website13", "website14", "website15", "website16", "website17", "website18" };

        DataContext = this;
    }

    private void CB_catego_Checked(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("this is an categorie");
    }

    private void CB_website_Checked(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("this is an website");
    }

and here is my XAML :

<ScrollViewer HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="97" Margin="10,209,0,0">
        <ListBox ItemsSource="{Binding Collection1}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <CheckBox Checked="CB_catego_Checked" Content="{Binding .}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>
    <ScrollViewer HorizontalAlignment="Left" Height="107" VerticalAlignment="Top" Width="97" Margin="10,97,0,0">
        <ListBox ItemsSource="{Binding Collection2}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <CheckBox Checked="CB_website_Checked" Content="{Binding .}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>

do you know if is it possible ? thanks a lot .




Aucun commentaire:

Enregistrer un commentaire