2012-08-28 104 views
1

我试图使用ListBox和ItemsSource属性显示来自YouTube的视频列表。在DataTemplate中使用名称空间DataType

我现在有什么作品(下),但现在我需要格式化我的数据。

<ListBox Name="lbVideos" ItemsSource="{Binding Source={StaticResource listOfVideos}}"/> 

为此,我使用了DataTemplate,但问题在于该类型是Google.YouTube.Video。

<Application x:Class="YouTube_Notifier.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Startup="AppStartup" 
    xmlns:src="clr-namespace:YouTube_Notifier" 
    xmlns:System="clr-namespace:System;assembly=mscorlib"> 
    <Application.Resources> 
     <DataTemplate DataType="{x:Type src:Google:YouTube:Video}"> 
     </DataTemplate> 
    </Application.Resources> 
</Application> 

上述结果在我得到的错误代码“类型‘SRC:Google.YouTube.Video’没有被发现。”

我在问什么是如何在DataTemplate中使用名称空间?

回答

6

包含你的类型的命名空间必须已在您的xmlns属性映射,即

xmlns:src="clr-namespace:YouTube_Notifier.Google.YouTube" 
{x:Type src:Video} 

又见namespace mapping referencereference for x:Type ...

+0

那么这是不是更容易我想。谢谢! :-) – Dumpen

相关问题