|
Ok. I figured out that the problem is with the "AllowMultiple = true" in the AttributeUsage attribute of the ExportUIVisualizerAttribute.
The problem is that the attribute still uses the IUIVisualizerMetaData which does not contain an ARRAY of Keys (and so won't match the AllowMultiple results).
Personally I don't see why you want AllowMultiple to be true, as why would you want to give a view multiple keys? If you still want to for what ever reason, you need to redefine how the UIVisualizer registration will work, particularly when multiple keys
are applied (do you simply register it multiple times using different keys?)
Anway I made the changes at my end if you want to include them do the following:
1. Copy the IUIVisualizerMetadata class and make a IUIVisualizerMetaDataMultiple class where the the keys are an array "string[] Key { get; }"
/// <summary>
/// Interface used to populate metadata we use for services (multiple being true).
/// </summary>
public interface IUIVisualizerMetadataMultiple
{
/// <summary>
/// Key used to export the UI - registered with the UIVisualizer.
/// </summary>
string[] Key { get; }
/// <summary>
/// The type being exported
/// </summary>
string ExportTypeIdentity { get; }
}
2. Update the UIVisualizer ImportMany call to use the new metadata interface from above.
private IEnumerable<Lazy<object, IUIVisualizerMetadataMultiple>> _locatedVisuals;
3. Replace the CheckForDynamicRegisters() with:
/// <summary>
/// Initialize any MEF-located views.
/// </summary>
private void CheckForDynamicRegisters()
{
if (!_haveLoadedVisuals) {
// If we have visuals, register them
foreach (var item in _locatedVisuals) {
Type type = FindType(item.Metadata.ExportTypeIdentity);
if (type != null) {
foreach (string sKey in item.Metadata.Key) {
Register(sKey, type);
}
}
}
// Clear the collection so we don't process twice.
_haveLoadedVisuals = true;
}
}
|