在XAML中的自定义对象上设置Type属性
我有以下转换器需要知道要解析的枚举类型。
I have the following converter which needs to know the Enum type to parse.
public class EnumToStringConverter : IValueConverter
{
public Type EnumType { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
// ...
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
// ...
}
}
然后我使用与样式相同的语法在XAML中声明类型。
Then I declare the type in XAML using the same syntax used for styles.
<UserControl x:Class="MyProject.PreferencesPage"
xmlns="..."
xmlns:converters="using:MyProject.Converters"
xmlns:model="using:MyProject.Model">
<UserControl.Resources>
<converters:EnumToStringConverter x:Key="EnumToStringConverter" EnumType="model:ResultSize" />
</UserControl.Resources>
<!-- ... -->
</UserControl>
我没有得到任何波浪线,但我在运行时得到一个解析错误。
I don't get any squiggle lines, but I get a parse error at runtime.
这是错误:
BingImageSearch.exe中出现"Windows.UI.Xaml.Markup.XamlParseException"类型的例外,但未在用户代码中处理
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in BingImageSearch.exe but was not handled in user code
附加信息:无法从文本'model:ResultSize'创建'Windows.UI.Xaml.Interop.TypeName'。 [行:14位置:82]
Additional information: Failed to create a 'Windows.UI.Xaml.Interop.TypeName' from the text 'model:ResultSize'. [Line: 14 Position: 82]
IIRC,此语法仅限于WPF&Silverlight中样式和模板的TargetType属性,这仍然是案件?
IIRC, this syntax was restricted to TargetType properties on styles and templates in WPF and Silverlight, is this still the case?
你好bendewey,
Hi bendewey,
我会在内部咨询,并在这里更新当我收到任何反馈时。
I will consult it internally, and update here when I get any feedback.
此致,