wpf xaml 数据模板选择器中的动态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16699627/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:51:03  来源:igfitidea点击:

Dynamic in xaml Data Template selector

wpfdatatemplateselector

提问by Bryan

Ok I found this wonderful idea on code project. link

好的,我在代码项目中发现了这个绝妙的主意。 关联

The idea is great add all your data templates to collection in your list box. Tell each one what to look for (a type) and what data template to use when it runs into that type. The problem is that the included source code is different from the on page code and I can't seen to get any combination of it to work. Even adding the missing quotation marks and changing the type to a local class instead of the non-accessible string and int32 classes.

这个想法很棒,将所有数据模板添加到列表框中的集合中。告诉每个人要查找的内容(一种类型)以及遇到该类型时要使用的数据模板。问题是包含的源代码与页面上的代码不同,我看不到它的任何组合工作。甚至添加缺少的引号并将类型更改为本地类而不是不可访问的字符串和 int32 类。

So the question is. What am I doing wrong?

所以问题是。我究竟做错了什么?

Bryan

布莱恩

回答by H.B.

Should be totally redundant when you have DataTemplate.DataType.

当你有DataTemplate.DataType.

(Example)

示例