如何在 XAML / Universal Windows 应用程序中使用类型引用?
How can I use a type reference in a XAML / Universal Windows app?
我想在自定义命令中封装框架导航,并以声明方式将此命令用作静态资源。我发现
Frame.Navigate(typeof(MainPage));
它需要一个类型参数(目标页面的类型)来导航。我的第一次尝试是使用一个通用的 ICommand 实现,它将目标页面的类型作为通用类型参数传递。从 x:TypeArguments
is not supported for Windows Store Apps 开始,我尝试定义一个 属性
public Type TargetType { get; set; }
为命令。但是又没有运气:如果我尝试通过 xaml 属性
设置 属性
`<NavigationCommand TargetType="MainPage">
我收到一个编译时错误
MainPage is not supported in a Windows universal project
这应该有效:
<NavigationCommand TargetType="ns:MainPage">
其中 ns
是用 xmlns:ns="using:TheNamespaceInCode"
声明的 XML 名称空间前缀
(注意:WinRT 不支持 WPF 中使用的 x:Type
标记扩展)
我想在自定义命令中封装框架导航,并以声明方式将此命令用作静态资源。我发现
Frame.Navigate(typeof(MainPage));
它需要一个类型参数(目标页面的类型)来导航。我的第一次尝试是使用一个通用的 ICommand 实现,它将目标页面的类型作为通用类型参数传递。从 x:TypeArguments
is not supported for Windows Store Apps 开始,我尝试定义一个 属性
public Type TargetType { get; set; }
为命令。但是又没有运气:如果我尝试通过 xaml 属性
设置 属性`<NavigationCommand TargetType="MainPage">
我收到一个编译时错误
MainPage is not supported in a Windows universal project
这应该有效:
<NavigationCommand TargetType="ns:MainPage">
其中 ns
是用 xmlns:ns="using:TheNamespaceInCode"
(注意:WinRT 不支持 WPF 中使用的 x:Type
标记扩展)