【发布时间】:2015-12-29 01:38:32
【问题描述】:
鉴于此DataTemplate:
<DataTemplate x:DataType="Color">
...
</DataTemplate>
我收到以下错误:
as 运算符必须与引用类型或可为空的类型一起使用('Color' 是不可为空的值类型)
当您跟踪错误时,它会带您为使用 as 运算符的视图自动生成代码。
public void DataContextChangedHandler(global::Windows.UI.Xaml.FrameworkElement sender, global::Windows.UI.Xaml.DataContextChangedEventArgs args)
{
global::Windows.UI.Color data = args.NewValue as global::Windows.UI.Color;
if (args.NewValue != null && data == null)
{
throw new global::System.ArgumentException("Incorrect type passed into template. Based on the x:DataType global::Windows.UI.Color was expected.");
}
this.SetDataRoot(data);
this.Update();
}
我知道{x:Bind} 是新的,但以防万一,有谁知道如何配置它以允许值类型,或者至少使用直接转换?
【问题讨论】:
标签: c# xaml windows-store-apps uwp