在DataTemplate DataType中使用命名空间

Dum*_*pen 2 data-binding wpf xaml namespaces datatemplate

我正在尝试使用ListBox和ItemsSource属性显示来自YouTube的视频列表.

我现在的工作(下图),但现在我需要格式化我的数据.

<ListBox Name="lbVideos" ItemsSource="{Binding Source={StaticResource listOfVideos}}"/>
Run Code Online (Sandbox Code Playgroud)

为此,我使用的是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>
Run Code Online (Sandbox Code Playgroud)

上面的代码导致我收到错误"Type'src:找不到Google.YouTube.Video".

我要问的是如何在DataTemplate中使用命名空间?

H.B*_*.B. 8

包含您的类型的命名空间需要已经映射到您的xmlns属性中,即

xmlns:src="clr-namespace:YouTube_Notifier.Google.YouTube" 
Run Code Online (Sandbox Code Playgroud)
{x:Type src:Video}
Run Code Online (Sandbox Code Playgroud)

另请参阅命名空间映射参考和... 的参考x:Type