Skip to content
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

Visual Studio design-time APIs don't allow setting ModelProperty with the 'System.Type' property type #31

Open
miniBivlidi opened this issue Sep 24, 2020 · 0 comments
Assignees

Comments

@miniBivlidi
Copy link

Environment:
Microsoft Visual Studio Professional 2019 Preview
Version 16.8.0 Preview 3.1

Issue:
Since information about runtime types is not available at design time, it's impossible to set a model property with the 'System.Type' type.

I tried setting a property value to TypeIdentifier:

var myTypeIdentifier = new TypeIdentifier("CustomControlLibrary.WpfCore.MyEnum");
ModelItem.Properties["MyType"].SetValue(myTypeIdentifier);

I also tried to set it to TypeDefinition:

var myTypeIdentifier = new TypeIdentifier("CustomControlLibrary.WpfCore.MyEnum");
var myTypeDefinition = MetadataFactory.ResolveType(ModelItem.Context, myTypeIdentifier );
ModelItem.Properties["MyType"].SetValue(myTypeDefinition);

However, none of these attempts was successful.

When I create TypeExtension using ModelFactory and set the TypeName property, the markup extension appears in XAML, but with a wrong type name. It doesn't contain an xmlns prefix:

var myTypeIdentifier = new TypeIdentifier("CustomControlLibrary.WpfCore.MyEnum");
var myTypeDefinition = MetadataFactory.ResolveType(ModelItem.Context, myTypeIdentifier );
var typeExtensionItem = ModelFactory.CreateItem(ModelItem.Context, new TypeIdentifier("System.Windows.Markup.TypeExtension"));
typeExtensionItem.Properties["TypeName"].SetValue(myTypeDefinition.FullName);
ModelItem.Properties["MyType"].SetValue(typeExtensionItem);

Generated XAML:

<lib:MyControl MyType="{x:Type TypeName=CustomControlLibrary.WpfCore.MyEnum}" >

It seems that design time has no public APIs to get an xmlns type prefix or add it to the root element.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants