3

我该如何进行这项工作?

public partial class MyWindow : View<MyViewModel>
{
}

其中 View 定义为

public class View<T> : Window where T : IViewModel, new()
{
}

XAML:

<local:View
x:Class="Project.MyWindow"
x:TypeArguments="ViewModels:MyViewModel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
xmlns:ViewModels="clr-namespace:Mynamespace.ViewModels;assembly=Mynamespace.ViewModels"
xmlns:local="clr-namespace:Project"
>

我收到此错误...名称 View 在名称空间 Project 中不存在...当然存在。

我得到这个错误,这真的让我感到困惑......“ http://schemas.microsoft.com/winfx/2006/xaml ”命名空间中不存在属性“TypeArguments” ......当然它确实存在。

关于如何在 wpf 中使用泛型作为 Windows 的基类的任何线索?

4

1 回答 1

5

这个问题的答案是永远不要在 xaml 中使用泛型。总是有更好的方法或解决方法。请参阅原始帖子的评论。

编辑!

感谢 Micky Duncan(参见上面的评论),可以通过调查这两个链接找到这个问题的正确答案:

http://msdn.microsoft.com/en-us/library/ms741843(v=vs.110).aspx http://www.codeproject.com/Articles/37317/Generic-Support-In-XAML

于 2013-07-29T11:28:57.390 回答