Skip to content

Add VB example to Xaml designer extensibility #3603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions docs/extensibility/xaml-designer-extensibility-migration.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
title: XAML Designer Extensibility Migration
ms.date: 04/17/2019
ms.date: 07/09/2019
ms.topic: conceptual
author: lutzroeder
ms.author: lutzr
manager: jillfra
dev_langs:
- csharp
- vb
monikerRange: vs-2019
---
# XAML designer extensibility migration
Expand Down Expand Up @@ -38,7 +41,7 @@ While third-party control libraries are compiled for the actual target runtime (

The surface isolation extensibility model doesn't allow for extensions to depend on actual control libraries, and therefore, extensions can't reference types from the control library. For example, *MyLibrary.designtools.dll* should not have a dependency on *MyLibrary.dll*.

Such dependencies were most common when registering metadata for types via attribute tables. Extension code that references control library types directly via [typeof](/dotnet/csharp/language-reference/keywords/typeof) is substituted in the new APIs by using string-based type names:
Such dependencies were most common when registering metadata for types via attribute tables. Extension code that references control library types directly via [typeof](/dotnet/csharp/language-reference/keywords/typeof) ([GetType](/dotnet/visual-basic/language-reference/operators/gettype-operator) in Visual Basic) is substituted in the new APIs by using string-based type names:

```csharp
using Microsoft.VisualStudio.DesignTools.Extensibility.Metadata;
Expand All @@ -62,6 +65,27 @@ public class AttributeTableProvider : IProvideAttributeTable
}
```

```vb
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Metadata
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Features
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Model

<Assembly: ProvideMetadata(GetType(AttributeTableProvider))>

Public Class AttributeTableProvider
Implements IProvideAttributeTable

Public ReadOnly Property AttributeTable As AttributeTable Implements IProvideAttributeTable.AttributeTable
Get
Dim builder As New AttributeTableBuilder
builder.AddCustomAttributes("MyLibrary.MyControl", New DescriptionAttribute(Strings.MyControlDescription))
builder.AddCustomAttributes("MyLibrary.MyControl", New FeatureAttribute(GetType(MyControlDefaultInitializer)))
Return builder.CreateTable()
End Get
End Property
End Class
```

## Feature providers and Model API

Feature providers are implemented in extension assemblies and loaded in the Visual Studio process. `FeatureAttribute` will continue to reference feature provider types directly using [typeof](/dotnet/csharp/language-reference/keywords/typeof).
Expand All @@ -80,6 +104,16 @@ if (type != null && buttonType != type.IsSubclassOf(buttonType))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind fixing the C# sample too? I'm pretty sure this was meant to say this:
if (type != null && type.IsSubclassOf(buttonType)) or shorter to match your change:
if (type?.IsSubclassOf(buttonType) == true)

```

```vb
Dim type As TypeDefinition = ModelFactory.ResolveType(
item.Context, New TypeIdentifier("MyLibrary.MyControl"))
Dim buttonType As TypeDefinition = ModelFactory.ResolveType(
item.Context, New TypeIdentifier("System.Windows.Controls.Button"))
If type?.IsSubclassOf(buttonType) Then

End If
```

APIs removed from the surface isolation extensibility API set:

* `ModelFactory.CreateItem(EditingContext context, object item)`
Expand Down Expand Up @@ -117,7 +151,7 @@ APIs that use `TypeDefinition` instead of <xref:System.Type>:
* `ModelService.Find(ModelItem startingItem, Predicate<Type> match)`
* `ModelItem.ItemType`
* `ModelProperty.AttachedOwnerType`
* `ModelProperty.PropertyType
* `ModelProperty.PropertyType`
* `FeatureManager.CreateFeatureProviders(Type featureProviderType, Type type)`
* `FeatureManager.CreateFeatureProviders(Type featureProviderType, Type type, Predicate<Type> match)`
* `FeatureManager.InitializeFeatures(Type type)`
Expand All @@ -134,7 +168,7 @@ APIs that use `ModelItem` instead of <xref:System.Object>:
* `ModelItemDictionary.Remove(object key)`
* `ModelItemDictionary.TryGetValue(object key, out ModelItem value)`

Known primitive types like `int`, `string`, or `Thickness` can be passed to the Model API as .NET Framework instances and will be converted to the corresponding object in the target runtime process. For example:
Known primitive types like `Int32`, `String`, or `Thickness` can be passed to the Model API as .NET Framework instances and will be converted to the corresponding object in the target runtime process. For example:

```csharp
using Microsoft.VisualStudio.DesignTools.Extensibility.Features;
Expand All @@ -150,6 +184,20 @@ public class MyControlDefaultInitializer : DefaultInitializer
}
```

```vb
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Features
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Model

Public Class MyControlDefaultInitializer
Inherits DefaultInitializer

Public Overrides Sub InitializeDefaults(item As ModelItem)
item.Properties!Width.SetValue(800.0)
MyBase.InitializeDefaults(item)
End Sub
End Class
```

## Limited support for .design.dll extensions

If any *.designtools.dll* extension is discovered for a control library, it is loaded first and discovery for *.design.dll* extensions is skipped.
Expand Down