小编Bar*_*lue的帖子

如何在 C# WPF 中选中/取消选中列表框中的所有复选框?

我有一个ListBox包含复选框,DataTemplate并且有两个按钮“全选”和“取消全选”。我想通过单击选择和取消选择按钮来使该复选框选中所有并取消选中所有,我想INotifyPropertyChanged在课堂上实现。我怎样才能做到这些事情?

感谢您提前的回答..

XAML代码

  <StackPanel>
        <ListBox Name="lstUserDefination" 
 ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionMode="Multiple">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <ListBoxItem>
                    <CheckBox Name="chkUser" Content="{Binding AuthorityName}"/>
                    </ListBoxItem>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>
Run Code Online (Sandbox Code Playgroud)

C# 代码

   public partial class UserDefinationEdit : Window
{
    public ObservableCollection<Authority> authorityList { get; set; }

    public UserDefinationEdit()
    {
        InitializeComponent();
        CreateCheckBoxList();
        lstUserDefination.ItemsSource = authorityList;
    }


    private void Window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.LeftButton == MouseButtonState.Pressed)
        {
            DragMove();
        }
    }

    public void CreateCheckBoxList()
    {
        authorityList = new ObservableCollection<Authority>();

        authorityList.Add(new Authority() {AuthorityValue = 0, AuthorityName …
Run Code Online (Sandbox Code Playgroud)

c# wpf checkbox listbox observablecollection

3
推荐指数
1
解决办法
7370
查看次数

标签 统计

c# ×1

checkbox ×1

listbox ×1

observablecollection ×1

wpf ×1