0

经过一番研究,我发现我们不能在 Page 中使用泛型类型,如下所示:

public class MyPage<T> : Page where T : class

原因是我们无法告诉页面的 xaml 文件这是什么 T(如果我错了,请纠正我)。我在互联网上看到了一种可能的解决方案,它正在发生这样的事情:

//this page has only cs file 
public class MyPage<T> : Page where T : class
{
}


//this page again is constructed only from cs file
public class BasePage : MyPage<ViewModel>
{
}

//at last we have a page with xaml file that can be shown
public class MainPage : BasePage
{
}

正如你所看到的,这段代码看起来很奇怪,我真的不喜欢这个解决方案。

那么有人可以为这个问题提供一个好的解决方案吗?也许举个例子。

4

1 回答 1

0

您不需要,因为当前的 XAML 规范不支持这一点。顺便说一句,创建页面是一个好主意,特别是对于强类型化视图模型属性。顺便说一句,平台团队知道这个请求。但是,IView<T>如果您想要解决方法,您可以实施。

于 2016-03-31T20:28:30.093 回答