Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox Column - cascade select #135

Open
turowicz opened this issue Oct 19, 2022 · 7 comments
Open

Checkbox Column - cascade select #135

turowicz opened this issue Oct 19, 2022 · 7 comments

Comments

@turowicz
Copy link

How can I make it so when I check a hierarchy node, then all subitems get also checked in a cascade way?

@turowicz
Copy link
Author

cc @grokys @wieslawsoltes

@SuperJMN
Copy link
Contributor

SuperJMN commented Oct 19, 2022

How can I make it so when I check a hierarchy node, then all subitems get also checked in a cascade way?

I imagine that you want something like this: WalletWasabi/WalletWasabi#9089 (review)

You will want a MultiSelector
And a column like this: https://github.com/SuperJMN/WalletWasabi/blob/465980eb6b900e8ef050f2582ad872f0f9157b09/WalletWasabi.Fluent/ViewModels/CoinSelection/Core/ColumnFactory.cs#L103

If you need more help, ping me and I will see if I can prepare a sample for you.

@turowicz
Copy link
Author

@SuperJMN a sample would be lovely.

I tried this but it doesn't trigger a draw. This mean that I need to scroll the list to see the visual changes.

    public class TreeItem : INotifyPropertyChanged
    {
        private bool _checked;

        public TreeItem()
        {
            Children.CollectionChanged += DataCollectionChanged;
        }

        public string Display { get; set; }

        public dynamic Object { get; set; }

        public bool Checked
        {
            get
            {
                return _checked;
            }
            set
            {
                _checked = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(nameof(Checked)));
                }
            }
        }

        public ObservableCollection<TreeItem> Children { get; set; } = new ObservableCollection<TreeItem>();

        public event PropertyChangedEventHandler? PropertyChanged;

        public override string ToString()
        {
            return Display;
        }

        private void DataCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.OldItems != null)
            {
                foreach (INotifyPropertyChanged item in e.OldItems)
                {
                    item.PropertyChanged -= ItemPropertyChanged;
                }
            }

            if (e.NewItems != null)
            {
                foreach (INotifyPropertyChanged item in e.NewItems)
                {
                    item.PropertyChanged += ItemPropertyChanged;
                }
            }
        }

        public static void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is TreeItem item)
            {
                var isChecked = item.Checked;

                foreach(var child in item.Children)
                {
                    child.Checked = isChecked;

                    ItemPropertyChanged(child, null);
                }
            }
        }
    }

@turowicz
Copy link
Author

I feel like this is a standard feature to be expected from a Tree control with checkboxes. It should have been implemented in #127

@turowicz
Copy link
Author

@SuperJMN @grokys @wieslawsoltes anyone please help, I'm stuck on this:

Screencast.from.2022-10-22.13-24-27.webm

@turowicz
Copy link
Author

It only updates the drawing after the CheckboxColumn items fall below the fold

@Coloryr
Copy link

Coloryr commented Jan 16, 2023

Only this code can be used now

<TreeDataGrid.Resources>
                        <DataTemplate x:Key="FileNameCell1" DataType="m:FileTreeNodeModel">
                            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" />
                        </DataTemplate>
Columns =
                {
                    new TemplateColumn<FileTreeNodeModel>(
                            "Name",
                            "FileNameCell1",
                            options: new ColumnOptions<FileTreeNodeModel>
                            {
                                CanUserResizeColumn = false
                            }),

GIF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants