Windows 8 Store Application Support for x:TypeArguments

心已入冬 提交于 2019-12-31 05:01:29

问题


I'd like to know the same thing as this: Silverlight 4 Support for x:TypeArguments ... but for Windows 8 Store Apps.

Why is x:TypeArguments available if it doesnt work? Or am I missing something? The MainPage.i.g.cs file is auto-generated with a non-generic base class even though x:TypeArguments is defined in the XAML - so of course it doesn't compile.

I can get it working with the proposed work-around of having a "typedef" base class which specifies the generic type, but this feels pretty hacky to me..

// A generic PageBase, containing standard ViewModel-related utilities
internal abstract class PageBase<T> : Windows.UI.Xaml.Controls.Page where T : ViewModelBase
{
    protected abstract T ViewModel { get; }
    ...
}

// The hack...
internal abstract class MainPageTypeDef : PageBase<MainViewModel>
{
    // No code goes here...
}

// The page itself
internal sealed partial class MainPage : MainPageTypeDef
{
}

<views:PageBase
    ...
    x:Class="Namespace.MainView"
    x:TypeArguments="store:MainViewModel">

Anyone know if there is a way of not having the "typedef" class?

Many thanks, Jon


回答1:


Sadly it's not possible. I got a definitive answer from a Microsoft contact: "I can confirm that but x:TypeArguments use in Xaml is not a supported scenario Windows Store Apps."




回答2:


I'm pretty sure the answer is the same as for Silverlight. WinRT Xaml is in many ways closer to Silverlight Xaml than it is to WPF, and they've made all sorts of strange decisions in what to include and what not to.



来源:https://stackoverflow.com/questions/14478469/windows-8-store-application-support-for-xtypearguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!