镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
This repository was archived by the owner on May 7, 2022. It is now read-only.
This repository was archived by the owner on May 7, 2022. It is now read-only.

Binding SelectedItems crash #56

Open

Description

@CBenghi

Hello,

maybe I'm doing something very silly, but if I try to bind the SelectedItems property of the control I get exceptions as the dependencyproperty seems to be null, even if I initialised it.

Is there something big I'm missing?

Thanks,
Claudio

Activity

  1. CBenghi commented on Dec 10, 2021

    @CBenghi
    Author

    I've looked at the code and I think the problem lies with the initialization of the SelectedItems property.

    It is initialized at the following lines in the constuctor:

    public MultiSelectTreeView()
    {
    SelectedItems = new ObservableCollection<object>();

    whereas it should be initialized in the metadata of the DependencyProperty with something like the following:

    public static DependencyProperty SelectedItemsProperty = DependencyProperty.Register(
    	"SelectedItems",
    	typeof(IList),
    	typeof(MultiSelectTreeView),
    	new FrameworkPropertyMetadata(
    		new ObservableCollection<object>(), 
    		FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, 
    		OnSelectedItemsPropertyChanged)
    	);

    I'm happy to post a PR if this solution works for you.

  2. ygoe commented on Dec 11, 2021

    @ygoe
    Owner

    I think I've never done that. My approach was to bind each item's IsSelected property (this is prone to missed notifications while items are virtualised away) or do the selection stuff in the view code (.xaml.cs) instead. I'm not using this code anymore and I can't offer much support for it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions