locked
[UWP][C++] Convert IStorageItemInformation to IStorageItem get from FileInformationFactory? RRS feed

  • Question

  • I see such code in the "StorageDataSource and GetVirtualizedFilesVector" sample. Is the item a IStorageItemInformation ?

    DataTemplate^ FileFolderTemplateSelector::SelectTemplateCore(Object^ item, DependencyObject^ container)
    {
        // determine the type of the item and set the correct template to display the item.
        auto folder = dynamic_cast<StorageFolder^>(item);
        return (folder != nullptr) ? FolderInformationTemplate : FileInformationTemplate;
    }

    So it is safe to just dynamic_cast  IStorageItemInformation to IStorageItem get from FileInformationFactory?


    • Edited by Exilerrr Wednesday, June 8, 2016 8:42 AM
    Wednesday, June 8, 2016 8:41 AM

Answers

  • Hello Exilerrr,

    Welcome to the Developing Universal Windows apps forum! 

    First of all, the item is an Object, it can be everything and it is related to your item source.  In this code, as the source is:

     itemsViewSource->Source = fileInformationFactory->GetVirtualizedItemsVector();

    I think you are right on this, the item is the IStorageItemInformation object.

    >>So it is safe to just dynamic_cast  IStorageItemInformation to IStorageItem get from FileInformationFactory?

    For this I've checked some details from here:

    If I understand right, I think it's OK for us to dynamic_cast  IStorageItemInformation to StorageFolder. But I cannot find any document about IStorageItem. However I've tested it with some code which does not return any problem. So I think the cast is OK.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Exilerrr Thursday, June 9, 2016 1:34 PM
    Thursday, June 9, 2016 6:33 AM

All replies

  • Hello Exilerrr,

    Welcome to the Developing Universal Windows apps forum! 

    First of all, the item is an Object, it can be everything and it is related to your item source.  In this code, as the source is:

     itemsViewSource->Source = fileInformationFactory->GetVirtualizedItemsVector();

    I think you are right on this, the item is the IStorageItemInformation object.

    >>So it is safe to just dynamic_cast  IStorageItemInformation to IStorageItem get from FileInformationFactory?

    For this I've checked some details from here:

    If I understand right, I think it's OK for us to dynamic_cast  IStorageItemInformation to StorageFolder. But I cannot find any document about IStorageItem. However I've tested it with some code which does not return any problem. So I think the cast is OK.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Exilerrr Thursday, June 9, 2016 1:34 PM
    Thursday, June 9, 2016 6:33 AM
  • So we can cast it to StorageFolder and StorageFile, and check if one is successful.
    And IStorageItem is a Base Type of StorageFolder and StorageFile, so if the Object is one of them, it should be a IStorageItem, am I right?




    • Edited by Exilerrr Thursday, June 9, 2016 2:13 PM
    Thursday, June 9, 2016 1:41 PM