UWP Windows 10 应用程序中页面/视图的通用基类

5
在使用Template10的UWP-Windows 10 C#/XAML应用程序中,我正在尝试让我的页面/视图继承自从Windows.UI.Xaml.Controls.Page继承的基类。 这一直在正常工作,但是当我尝试使基类成为通用类型,并在子类和XAML中包含一个类型参数时,它就无法工作:
namespace App.Views 
{
    public abstract class InfoListViewBase<M> : Page where M : InfoListViewModelBase
    {

        public InfoListViewBase() { }

    }

    public sealed partial class ModelPage : InfoListViewBase<Model>
    {
        public Model()
        {
            InitializeComponent();
            NavigationCacheMode = NavigationCacheMode.Disabled;
        }
    }
}

<local:InfoListViewBase 
    x:Class="App.Views.ModelPage"
    x:TypeArguments="l:Model"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Behaviors="using:Template10.Behaviors"
    xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:controls="using:Template10.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:App.Views"
    xmlns:l="using:Library"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

</local:InfoListViewBase>

我收到的错误信息是:
The name "InfoListViewBase`1" does not exist in the namespace "using:App.Views".

每次我在XAML代码中添加x:TypeArguments="l:Model"这一行时,就会出现错误提示。在Visual Studio进行多次重建、清理等操作都没有解决这个问题。请问,在XAML中实现泛型的过程中我做错了什么吗?
1个回答

6
很遗憾,UWP应用程序中仍不支持XAML中的通用参数。目前无法在XAML中使用x:TypeArguments。但是您可以参考此线程尝试解决问题。
如果您仍希望使用此功能,您也可以将此功能请求提交到UserVoice

1
很遗憾听到这个消息。感谢您的回答! - cloudcrypt
请在此处投票(https://developercommunity.visualstudio.com/idea/610869/support-generic-type-arguments-in-uwp-xaml.html)。 - Shimmy Weitzhandler

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接