3

I am trying to show a list of videos from YouTube using a ListBox and the ItemsSource property.

What I have right now works (Below), but now I need to format my data.

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

For that i'm using a DataTemplate but the problem is that the type is 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>

The code above results in me getting the error "Type 'src:Google.YouTube.Video' was not found."

What I am asking is how do I use namespaces in a DataTemplate?

1 Answer 1

9

The namespace containing your type needs to already be mapped in your xmlns attribute, i.e.

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

See also the namespace mapping reference and the reference for x:Type...

Sign up to request clarification or add additional context in comments.

1 Comment

Well that was easier than I thought. Thank you! :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.