我是Windows手机开发的新手,所以请原谅我,如果我的问题是愚蠢的。
我开发了一个简单的泛型类,旨在成为WP7应用程序中所有页面的基类。在这里:
namespace Subway.Rails
{
public class Screen<TModel> : PhoneApplicationPage where TModel: class, new()
{
private static readonly DependencyProperty ModelProperty = DependencyProperty.Register("Model", typeof(TModel),
typeof (Screen<TModel>),
new PropertyMetadata(new TModel()));
public TModel Model
{
get { return GetValue(ModelProperty) as TModel; }
set { SetValue(ModelProperty, value); }
}
}
}
但是,当我尝试使用x:TypeArguments
指令
<rails:Screen x:TypeArguments="models:NotesStorage" xmlns:rails="clr-namespace:Subway.Rails;assembly=Subway.Rails" ...
并将* .xaml.cs文件中的基本类型加倍
public partial class HomeView : Screen<NotesStorage>
我收到运行时错误
Error 7 Using the generic type 'Subway.Rails.Screen<TModel>' requires 1 type arguments D:\development\labs\mobilelab\Subway.Notes\Subway.Notes\obj\Debug\Views\HomeView.g.cs 37 50 Subway.Notes
在生成的文件中。
有没有办法在XAML中实例化通用页面?
答案 0 :(得分:1)
虽然我找不到任何正式的说明(总是很难找到不支持的功能的文档):当它是not supported in Silverlight时,它在Windows Phone上不可用。
您看到的错误消息似乎证实了这一点。