Use a ShellFile object using Windows API Code Pack for Microsoft

寵の児 提交于 2019-12-08 10:04:55

问题


Windows API Code Pack for Microsoft can be downloaded from here. That is a really nice library and it has great examples. For example if I open the solution WindowsAPICodePack10 that comes in the zip from downloading the code pack (it only contains the libraries I added a win forms and wpf application)

then I am able to use the library very easily for example in my wpf application I can drag:

ExplorerBrowser user control (note I have to add references to the libraries that came with the solution)

and then with a button I can populate that control with this lines of code:

        // Create a new CommonOpenFileDialog to allow users to select a folder/library
        CommonOpenFileDialog cfd = new CommonOpenFileDialog();

        // Set options to allow libraries and non filesystem items to be selected
        cfd.IsFolderPicker = true;
        cfd.AllowNonFileSystemItems = true;

        // Show the dialog
        CommonFileDialogResult result = cfd.ShowDialog();

        // if the user didn't cancel
        if (result == CommonFileDialogResult.Ok)
        {
            // Update the location on the ExplorerBrowser
            ShellObject resultItem = cfd.FileAsShellObject;
            explorerBrowser1.NavigationTarget = resultItem;
            //explorerBrowser1.Navigate(resultItem);
        }

and after that I am able to have something like:

That is amazing but I don't understand Microsoft. If they give you those libraries they should make it easy to customize that user control. the reason why I downloaded those libraries is because I need to place files from a specific directory on a stackpanel and be able to have the same functionality that you get with files on explorer (able to drag files, get context menu when right clicking file, dropping files to that container etc)

anyways I don't need all that functionality. from studing the library I think that user control contains a ShellContainer object and it's childern are ShellFiles maybe.

So from this library I will like to create a ShellFile object and place it in a StackPanel. after tedious studing of the library I finally found out how to instantiate an object from shellFile (ShellFile class is abstract) :

string filename = @"C:\Program Files (x86)\FileZilla FTP Client\filezilla.exe"; \\random file
ShellFile shellFile = ShellFile.FromFilePath(filename);

now it will be nice if I could place that file in a container. I am not able to instantiate a ShellConteiner object becaue it is abstract too. so how Will I bee able to place that shell file on a canvas for example?

or maybe I could extract the properties that I need and create a user control that will represent a shellFile. I know how to get the thumbnail I can do something like:

        string filename = @"C:\Program Files (x86)\FileZilla FTP Client\filezilla.exe";

        ShellFile shellFile = ShellFile.FromFilePath(filename);
        System.Drawing.Bitmap btm = shellFile.Thumbnail.ExtraLargeBitmap;

来源:https://stackoverflow.com/questions/7934238/use-a-shellfile-object-using-windows-api-code-pack-for-microsoft

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!