Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using namespace in DataTemplate DataType

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?

like image 532
Dumpen Avatar asked Dec 12 '25 17:12

Dumpen


1 Answers

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...

like image 122
H.B. Avatar answered Dec 14 '25 07:12

H.B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!