经过一番研究,我发现我们不能在 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
{
}
正如你所看到的,这段代码看起来很奇怪,我真的不喜欢这个解决方案。
那么有人可以为这个问题提供一个好的解决方案吗?也许举个例子。