UWP Windows 10 App 中 Pages/Views 的通用基础 class
Generic base class for Pages/Views in UWP Windows 10 App
在使用 Template10 的 UWP-Windows 10 C#/XAML 应用程序中,我目前正在尝试让我的 pages/views 从继承的基础 class 继承来自 Windows.UI.Xaml.Controls.Page
.
这一直正常工作,但是当我尝试使基础 class 通用,并按以下方式在子 class 和 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 中实现泛型时我做错了什么吗?
遗憾的是,XAML 中的通用参数在 UWP 应用中仍然不受支持。您目前无法在 XAML 中使用 x:TypeArguments
。但是您可以参考 来尝试解决方法。
如果您仍然需要此功能,也可以将此功能请求提交至 UserVoice。
在使用 Template10 的 UWP-Windows 10 C#/XAML 应用程序中,我目前正在尝试让我的 pages/views 从继承的基础 class 继承来自 Windows.UI.Xaml.Controls.Page
.
这一直正常工作,但是当我尝试使基础 class 通用,并按以下方式在子 class 和 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 中实现泛型时我做错了什么吗?
遗憾的是,XAML 中的通用参数在 UWP 应用中仍然不受支持。您目前无法在 XAML 中使用 x:TypeArguments
。但是您可以参考
如果您仍然需要此功能,也可以将此功能请求提交至 UserVoice。