question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to set the property of type 'Type' from xaml?

See original GitHub issue

I have a WinUI/UWP project. In my custom control I have a property of type Type. I tried to set it from xaml like ControlTemplate.TargetType property, but got an exception on InitializeComponent.

Windows.UI.Xaml.Markup.XamlParseException: 'The text associated with this error code could not be found.

Failed to assign to property ‘App11.MyControl.SomeProperty’. [Line: 17 Position: 26]’

Is there a way to set such properties from xaml?

Sample control

public class MyControl : Button
{        
        public Type SomeProperty { get; set; }
}

Xaml

<local:MyControl SomeProperty="Button" />

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
evelynwu-msftcommented, May 27, 2020

Thanks! You’re right, the Windows.UI.Xaml.Markup.XamlParseException text displayed by VS tricked me into thinking that you were using UWP XAML rather than WinUI 3.

As it turns out, this is a known issue that we’re already working on fixing, but we appreciate the report nonetheless!

1reaction
RealTommyKleincommented, Jun 15, 2020

This will be fixed in the WinUI 3 Preview 2 release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting a custom type property in XAML using a static ...
I'm trying to determine if there's a way to set a custom type to a property through XAML by using a static method's...
Read more >
Setter.Property Property (Windows.UI.Xaml) - UWP
You can use a Setter to style an attached property. In this case the dependency property name is a qualified name in XAML...
Read more >
Style.TargetType Property (Windows.UI.Xaml) - UWP
Gets or sets the type for which the style is intended. TargetType can be used to declare an implicit style resource if there's...
Read more >
XAML Magic: Attached Properties
Fundamentally, the Dependency Property system is a way to first define a property and register it with the overall Dependency Property system, ...
Read more >
Setting property of type System.Type in XAML doesn't set ...
The Xaml compiler generally doesn't inspect property values themselves, so it doesn't know to generate type info for a property of type System....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found