在使用Template10的UWP-Windows 10 C#/ XAML应用程序中,我目前正在尝试使我的页面/视图继承自从Windows.UI.Xaml.Controls.Page继承的基类.这一直可以正常工作,但是当我尝试使基类具有通用性,并通过以下方式在子类和X...

在使用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".
每当我将X:TypeArguments =“ l:Model”添加到XAML时,都会显示该错误.
在Visual Studio中进行多次重建,清理等操作尚未解决该问题.
在XAML中实现泛型时,我做错了什么?
解决方法:
不幸的是,UWP应用程序仍不支持XAML中的通用参数.您目前无法在XAML中使用x:TypeArguments.但是您可以参考this thread来尝试解决方法.
如果仍然需要此功能,也可以将该功能请求提交给UserVoice.
本文标题为:c#-UWP Windows 10 App中页面/视图的通用基类


基础教程推荐
- dotnet core 在CentOS下 使用libreoffice 把Office 转换成pdf 2023-09-26
- 如何使用C#代码创建快捷方式文件详解 2022-12-31
- C#线程委托实现原理及方法解析 2023-03-09
- c#批量抓取免费代理并且验证有效性的实战教程 2022-12-26
- C# 线程安全详解 2023-05-05
- .net core cshtml前台文件修改后,刷新页面无法时时预览,只能重新启动调试的问题解决 2023-09-27
- C# 利用Selenium实现浏览器自动化操作的示例代码 2023-03-09
- Linux中发布.netcore时启用ssl 2023-09-26
- 详细聊聊C#的并发机制优秀在哪 2023-05-16
- WPF基础教程之形状画刷与变换详解 2023-01-11