Pri*_*nes 5 generics wpf inheritance xaml
我该如何进行这项工作?
public partial class MyWindow : View<MyViewModel>
{
}
Run Code Online (Sandbox Code Playgroud)
其中视图定义为
public class View<T> : Window where T : IViewModel, new()
{
}
Run Code Online (Sandbox Code Playgroud)
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"
>
Run Code Online (Sandbox Code Playgroud)
我收到此错误...命名空间 Project 中不存在名称 View...当然它确实存在。
我得到这个错误,这真的让我很困惑...“ http://schemas.microsoft.com/winfx/2006/xaml ”命名空间中不存在属性“TypeArguments” ...当然它确实存在。
关于如何在 wpf 中使用泛型作为 Windows 基类的任何线索?
这个问题的答案是永远不要在 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
归档时间: |
|
查看次数: |
6783 次 |
最近记录: |