MultiSelectionKind SameType don't work for folders and files

Shell for WPF Forum

Posted 1 year ago by BenjaminLopVic - France
Version: 22.1.4
Platform: .NET 4.6
Environment: Windows 10 (64-bit)
Avatar

Hello,

I am currently encountering an issue with the ShellTreeListBox component. I am trying to select multiple files or folders, but not both at the same time, so I have set the following properties for my control:

<shell:ShellTreeListBox MultiSelectionKind="SameType" SelectionMode="Extended" RootSpecialFolderKind="LocalDocuments" CanIncludeFiles="True"/>

However, even with these properties set, I am still able to select both files and folders at the same time. I was expecting the "SameType" property to differentiate between files and folders in the ShellTreeListBox. Is this a bug or is this the normal behavior?

I would appreciate any suggestions or solutions to this problem.

Thank you in advance for your help.

Benjamin.

Comments (4)

Answer - Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Benjamin,

The MultiSelectionKind="SameType" is a feature of the core TreeListBox control that compares the item being selected and the existing active item to ensure they are of the same .NET Type.  ShellTreeListBox inherits this functionality, however all items (folders and files) in the TreeListBox are wrapped with ShellObjectViewModel instances, so their Type is always the same.  That means that use of the SameType won't work for this scenario.

One idea I had to work around that might be to make a class that inherits ShellObjectViewModel named FolderShellObjectViewModel.  Then override the ShellObjectItemAdapter.CreateShellObjectViewModel.  If shellObject.Kind == ShellObjectKind.Folder, create and return an instance of FolderShellObjectViewModel instead.  Otherwise return the base method's result.  This would make the Types be different from folders and other things.  There are some other Kind values you might wish to lump into building a FolderShellObjectViewModel too, but that gives a general idea of one way to hopefully get it working how you wanted.


Actipro Software Support

Posted 1 year ago by BenjaminLopVic - France
Avatar

Thank you for your response, I followed your suggestion and the Types are now different for folders and other items. It's working as expected now.

However, I have an additional question, when I redefine the itemAdapter like this :

<shell:ShellTreeListBox.ItemAdapter>
    <model:NewShellObjectItemAdapter/>
</shell:ShellTreeListBox.ItemAdapter>

with this ItemAdapter : 

internal class NewShellObjectItemAdapter : ShellObjectItemAdapter
{
    protected override ShellObjectViewModel CreateShellObjectViewModel(TreeListBox ownerControl, IShellObject shellObject)
    {
        if(shellObject.Kind == ShellObjectKind.Folder)
        {
            return new FolderShellObjectViewModel(shellObject);
        }

        return base.CreateShellObjectViewModel(ownerControl, shellObject);
    }
}

I get an error (XDG0010) saying that it's not a valid value, but it still works. Do you know why ?

Thank you again for your help.

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

If XDG0010 is a XAML designer error (I assume that's what XDG means), the Visual Studio designer is buggy and doesn't always recognize types properly.  If that's all it is and it's working at run-time, then everything in your code is fine and you should be able to safely ignore that error.  It will probably disappear as soon as you close the XAML file.


Actipro Software Support

Posted 1 year ago by BenjaminLopVic - France
Avatar

Thank you for your explanation and thank you again for your help.

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.