I've created an attached Type
DependencyProperty
in my project. Now, when using it with a type other than in the default namespace i get a XamlParseException
with the error message Failed to create a 'System.Type' from the text 'local:SomeClass'.
. Using e.g. Button
or Grid
as value does not throw an exception.
Classes to reproduce the issue:
namespace TypePropertyTest
{
public class SomeClass
{ }
}
Class containing the attached DP:
namespace TypePropertyTest
{
using System;
using Windows.UI.Xaml;
public static class TypeProperties
{
public static readonly DependencyProperty MyTypeProperty =
DependencyProperty.RegisterAttached(
"MyType",
typeof(Type),
typeof(TypeProperties),
new PropertyMetadata(null));
public static void SetMyType(DependencyObject d, Type type) => d.SetValue(MyTypeProperty, type);
public static Type GetMyType(DependencyObject d) => (Type)d.GetValue(MyTypeProperty);
}
}
MainPage.xaml:
<Page
x:Class="TypePropertyTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="using:TypePropertyTest"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid local:TypeProperties.MyType="local:SomeClass">
</Grid>
</Page>
The project targets version 1803 (10.0; Build 17134)
with the Fall Creators Update (10.0; Build 16299)
being the minimum version.
Apparently, the issue can be resolved by updating the target version of the project to a version >= 1809
(tested with 1809
and 1903
).