microsoft / Windows-classic-samples

This repo contains samples that demonstrate the API used in Windows classic desktop applications.
Other
5.09k stars 3.23k forks source link

StorageProviderItemProperty does not allow blank icons #357

Open michaelfoster9 opened 3 months ago

michaelfoster9 commented 3 months ago

I am using the Cloud File Api to write a custom OneDrive-like sync client. I have a desire to have custom properties that are available in explorer.

When I register my CFAPI SyncRoot during installation, I can define custom properties as follows.

var initialPropDefinitions = syncRootInfo.StorageProviderItemPropertyDefinitions;
var customPropDefinitions = propertyManager.GetCustomPropertyDefinitions();
foreach (var propDef in customPropDefinitions)
{
   var osPropDef = new StorageProviderItemPropertyDefinition
   {
      DisplayNameResource = propDef.DisplayNameResource,
      Id = propDef.Id
   };
   initialPropDefinitions.Add(osPropDef);
}
_storageProvider.RegisterSyncRoot(syncRootInfo);

This works great. The properties I assign are available in windows explorer to add as columns.

My problem comes when I try to set the property values. Below is the code that I use to assign property values.

List<StorageProviderItemProperty> itemProperties = new List<StorageProviderItemProperty>();
customColumns.Add(new StorageProviderItemProperty() {
    Id=3,
    Value="Hello"
    IconResource = string.empty
};

await StorageProviderItemProperties.SetAsync(item, itemProperties);

This works well but, Explorer crashes whenever I use an empty IconResource. I can fix this by creating a blank icon. So I had an example where I have 3 properties, one actually has an icon and the other two are blank. The status column shows all of the icons and you can see that the blank icons are taking up real estate under the status column. Sure, I can arrange my properties so that all of the ones that have real icons are set first. But, I would really like a way to set property values without using an icon. Is there such a way? This seems like a bug that you can't have custom properties WITHOUT an Icon