Is DataType attribute allowed on DataTemplate element?

If I don’t use DataType attribute on the DataTemplate VS complaints on each data binding below because it does not know what type is bound to the element. That is not a compile error and does not prevent the app building.

If I use DataType attribute, and I usually do for Xamarin Froms apps when I create apps for Android and iOS I’m getting a compiler error

8>Views\ListPage.xaml : XamlC error : Value cannot be null.
8>Views\ListPage.xaml : XamlC error : Parameter name: type

Here is the XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
   xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:viewModels="clr-namespace:Wearable.Tizen.ViewModels;assembly=Wearable.Tizen"
   x:Class="Wearable.Tizen.Views.ListPage"
   NavigationPage.HasNavigationBar="False"
>
   <ListView ItemsSource="{Binding ItemList}" ItemTapped="List_ItemTapped" CachingStrategy="RecycleElement">
	  <ListView.ItemTemplate>
		 <DataTemplate x:DataType="viewModels:ViewModel">
			<ViewCell>
			   <Grid>
				  <Grid.ColumnDefinitions>
					 <ColumnDefinition Width="Auto" />
					 <ColumnDefinition />
				  </Grid.ColumnDefinitions>
				  <Image Grid.Column="0" Source="{Binding FrontImageSource}" WidthRequest="88" HeightRequest="66" />
				  <StackLayout Grid.Column="1" Orientation="Vertical">
					 <Label LineBreakMode="TailTruncation" Text="{Binding Name}" />
					 <StackLayout Orientation="Horizontal">
						<Label LineBreakMode="NoWrap" Text="Done: " />
						<Label LineBreakMode="TailTruncation" Text="{Binding LastDoneFormatted}" />
					 </StackLayout>
				  </StackLayout>
			   </Grid>
			</ViewCell>
		 </DataTemplate>
	  </ListView.ItemTemplate>
   </ListView>
</ContentPage>

Is this attribute banned from usage on Tizen or the usage style should be different, maybe the namespace or something else?

Hello,

As far as the Tizen .NET overview goes…


If the attribute/feature is supported on .NET Core/.NET Standard should be working on Tizen .NET applications.

In this guide there’s presence of a bit ‘DataBinding’ discussion, please have a look if this helps somehow.

To crosscheck if there’s support for the specific attribute you’re looking for, you can post an Issue on this repo also, might get a response from the development team.

I take it as it should work but apparently it doesn’t so I believe this issue should be added to a list for fixing.

Hi,
DataTemplateSelector doesn’t seem to be a good choice here since you have the same template for all values of A .

Use DataTriggers for data science :

<DataTemplate>
    <StackPanel>
        <Image x:Name="image" />
        <TextBlock>Your text</TextBlock>
    </StackPanel>
    <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=A}" Value="ValueToCheck1">
            <DataTrigger.Setters>
                <Setter Property="Source" Value="Image1.png" TargetName="image" />
            </DataTrigger.Setters>
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=A}" Value="ValueToCheck2">
            <DataTrigger.Setters>
                <Setter Property="Source" Value="Image2.png" TargetName="image" />
            </DataTrigger.Setters>
        </DataTrigger>
    </DataTemplate.Triggers>
</DataTemplate>