3

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

我现在所拥有的工作(下),但现在我需要格式化我的数据。

<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 中使用命名空间?

4

1 回答 1

8

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

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

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

于 2012-08-28T12:23:05.257 回答