wpf 在 XAML x:Type 标记中使用泛型类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20496417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using generic types in XAML x:Type markup
提问by AwkwardCoder
I have the following XAML snippet and I want to include a generic parameter and I can't work out what I need to do?
我有以下 XAML 片段,我想包含一个通用参数,但我不知道我需要做什么?
I guess I'm going to have to created a markup extension to do this but I'm unsure how to get this to work with the x:Type attribute.
我想我将不得不创建一个标记扩展来做到这一点,但我不确定如何让它与 x:Type 属性一起工作。
DataType="{x:Type vm:FooViewModel<Bar>}"
回答by jnovo
Check the Generics in XAML documentationto see if it fits your scenario. You'd need to use x:TypeArguments; there are however some restrictions that you can check in the linked reference pages.
检查XAML 文档中的泛型以查看它是否适合您的方案。你需要使用x:TypeArguments; 但是,您可以在链接的参考页面中查看一些限制。

