Reputation: 15958
I'm trying to bind a class to a template.
<UserControl
x:Class="MyApp.Controls.PaperSelectControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<ScrollViewer>
<GridView x:Name="paperGrid"
ItemsSource="{x:Bind Papers}"
Width="400" Height="300" >
<GridView.ItemTemplate >
<DataTemplate x:DataType="MyApp.Model.Paper" >
<TextBlock Text="{x:Bind Color}"/>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</ScrollViewer>
</Grid>
</UserControl>
the MyApp.Model.Paper
is the class namespace.
namespace MyApp.Model {
public class Paper {
public string Name { get; set; }
public string Color { get; set; }
public string Thumb { get; set; }
}
}
But i always get the
Cannot resolve DataType MyApp.Model.Paper
error
I hope someone can help me to resolve this issue. Thank you.
Upvotes: 0
Views: 238
Reputation: 10627
As far as I known we cannot set the x:DataType
markup by namespace.class
format. For accessing your own custom types you can map a XAML namespace, this mapping is made by defining an xmlns
prefix. For example, xmlns:myTypes
defines a new XAML namespace that is accessed by prefixing all usages with the token myTypes:
.
So please add this mapping xmlns:model="using:MyApp.Model"
to your header markup list. And updated the XAML code for x:DataType
as follows: <DataTemplate x:DataType="model:Paper" >
, then build your project it will work.
More details please reference Mapping custom types to XAML namespaces and prefixes.
Upvotes: 1