Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a type reference in a XAML / Universal Windows app?

I want to encapsulate frame navigation in custom command und use this command declaratively as a static ressource. I found

Frame.Navigate(typeof(MainPage));

which expects a type parameter (type of the target page) to navigate to. My first attempt was to use a generic ICommand implementation that passes the type of the target page as generic type parameter. As of x:TypeArguments is not supported for Windows Store Apps, I tried to define a property

public Type TargetType { get; set; }

for the command. But no luck again: if I try to set the property via a xaml attribute

`<NavigationCommand TargetType="MainPage">

I get a compile-time error saying

MainPage is not supported in a Windows universal project
like image 948
ventiseis Avatar asked Dec 09 '25 08:12

ventiseis


1 Answers

This should work:

<NavigationCommand TargetType="ns:MainPage">

Where ns is an XML namespace prefix declared with xmlns:ns="using:TheNamespaceInCode"

(note: the x:Type markup extension used in WPF isn't supported in WinRT)

like image 53
Thomas Levesque Avatar answered Dec 12 '25 03:12

Thomas Levesque