我有一个动态数据透视项目模板,如下所示:
<controls:Pivot.ItemTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding Articles}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:DropPageSelector Content="{Binding}">
<local:DropPageSelector.hasImage>
<DataTemplate>
<!--Code-->
</DataTemplate>
</local:DropPageSelector.hasImage>
<local:DropPageSelector.noImage>
<DataTemplate>
<!--Code-->
</DataTemplate>
</local:DropPageSelector.noImage>
</local:DropPageSelector>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
这是我的 DropPageSelector 数据模板选择器类的代码:
class DropPageSelector : DataTemplateSelector
{
public DataTemplate noImage
{
get;
set;
}
public DataTemplate hasImage
{
get;
set;
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
News nws = item as News;
if (nws != null)
{
if ( nws.Image != null || nws.Image =="" )
{
return hasImage;
}
else
{
return noImage;
}
}
return base.SelectTemplate(item, container);
}
}
但是当我尝试运行代码时,出现以下错误:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'MS.Internal.NativeParseException' occurred in System.Windows.dll
A first chance exception of type 'System.Exception' occurred in System.Windows.dll
An unhandled exception of type 'System.Exception' occurred in System.Windows.dll
Additional information: Unspecified error
有谁知道为什么会这样?