Skip to content

Commit f2e2da7

Browse files
authored
Merge pull request #4976 from MicrosoftDocs/repo_sync_working_branch
Confirm merge from repo_sync_working_branch to master to sync with https://github.com/MicrosoftDocs/visualstudio-docs (branch master)
2 parents cc829e1 + e6fb415 commit f2e2da7

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

docs/extensibility/xaml-designer-extensibility-migration.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
title: XAML Designer Extensibility Migration
3-
ms.date: 04/17/2019
3+
ms.date: 07/09/2019
44
ms.topic: conceptual
55
author: lutzroeder
66
ms.author: lutzr
77
manager: jillfra
8+
dev_langs:
9+
- csharp
10+
- vb
811
monikerRange: vs-2019
912
---
1013
# XAML designer extensibility migration
@@ -38,7 +41,7 @@ While third-party control libraries are compiled for the actual target runtime (
3841

3942
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*.
4043

41-
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:
44+
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:
4245

4346
```csharp
4447
using Microsoft.VisualStudio.DesignTools.Extensibility.Metadata;
@@ -62,6 +65,27 @@ public class AttributeTableProvider : IProvideAttributeTable
6265
}
6366
```
6467

68+
```vb
69+
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Metadata
70+
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Features
71+
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Model
72+
73+
<Assembly: ProvideMetadata(GetType(AttributeTableProvider))>
74+
75+
Public Class AttributeTableProvider
76+
Implements IProvideAttributeTable
77+
78+
Public ReadOnly Property AttributeTable As AttributeTable Implements IProvideAttributeTable.AttributeTable
79+
Get
80+
Dim builder As New AttributeTableBuilder
81+
builder.AddCustomAttributes("MyLibrary.MyControl", New DescriptionAttribute(Strings.MyControlDescription))
82+
builder.AddCustomAttributes("MyLibrary.MyControl", New FeatureAttribute(GetType(MyControlDefaultInitializer)))
83+
Return builder.CreateTable()
84+
End Get
85+
End Property
86+
End Class
87+
```
88+
6589
## Feature providers and Model API
6690

6791
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).
@@ -80,6 +104,16 @@ if (type != null && buttonType != type.IsSubclassOf(buttonType))
80104
}
81105
```
82106

107+
```vb
108+
Dim type As TypeDefinition = ModelFactory.ResolveType(
109+
item.Context, New TypeIdentifier("MyLibrary.MyControl"))
110+
Dim buttonType As TypeDefinition = ModelFactory.ResolveType(
111+
item.Context, New TypeIdentifier("System.Windows.Controls.Button"))
112+
If type?.IsSubclassOf(buttonType) Then
113+
114+
End If
115+
```
116+
83117
APIs removed from the surface isolation extensibility API set:
84118

85119
* `ModelFactory.CreateItem(EditingContext context, object item)`
@@ -117,7 +151,7 @@ APIs that use `TypeDefinition` instead of <xref:System.Type>:
117151
* `ModelService.Find(ModelItem startingItem, Predicate<Type> match)`
118152
* `ModelItem.ItemType`
119153
* `ModelProperty.AttachedOwnerType`
120-
* `ModelProperty.PropertyType
154+
* `ModelProperty.PropertyType`
121155
* `FeatureManager.CreateFeatureProviders(Type featureProviderType, Type type)`
122156
* `FeatureManager.CreateFeatureProviders(Type featureProviderType, Type type, Predicate<Type> match)`
123157
* `FeatureManager.InitializeFeatures(Type type)`
@@ -134,7 +168,7 @@ APIs that use `ModelItem` instead of <xref:System.Object>:
134168
* `ModelItemDictionary.Remove(object key)`
135169
* `ModelItemDictionary.TryGetValue(object key, out ModelItem value)`
136170

137-
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:
171+
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:
138172

139173
```csharp
140174
using Microsoft.VisualStudio.DesignTools.Extensibility.Features;
@@ -150,6 +184,20 @@ public class MyControlDefaultInitializer : DefaultInitializer
150184
}
151185
```
152186

187+
```vb
188+
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Features
189+
Imports Microsoft.VisualStudio.DesignTools.Extensibility.Model
190+
191+
Public Class MyControlDefaultInitializer
192+
Inherits DefaultInitializer
193+
194+
Public Overrides Sub InitializeDefaults(item As ModelItem)
195+
item.Properties!Width.SetValue(800.0)
196+
MyBase.InitializeDefaults(item)
197+
End Sub
198+
End Class
199+
```
200+
153201
## Limited support for .design.dll extensions
154202

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

0 commit comments

Comments
 (0)