Reputation: 11
I have a problem - I want to bind into a GridView a class property which is a ObservableCollection.
the class code:
public class Moment
{
...
public ObservableCollection<Uri> PhotoFilePath { get; set; }
}
XAML
<GridView Grid.Row="0"
Name="PhotosGridView"
ItemsSource="{x:Bind moment}">
moment is a instance of Moment in MainPage.xaml
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:Moment">
<Image Width="75" Height="75">
<Image.Source>
<BitmapImage UriSource="{x:Bind PhotoFilePath}" />
here i get Severity Code Description Project File Line Suppression State Error Invalid binding path 'PhotoFilePath' : Cannot bind type 'System.Collections.ObjectModel.ObservableCollection(System.Uri)' to 'System.Uri' without a converter
</Image.Source>
</Image>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Thanks in advance
Upvotes: 0
Views: 3107
Reputation: 790
The UriSource property of BitmapImage expects type 'System.Uri' but you are trying to bind it to 'ObservableCollection of System.Uri'
(PhotoFilePath property of your Moment class is an ObservableCollection of System.Uri)
The answer is in the error message 'Cannot bind type 'System.Collections.ObjectModel.ObservableCollection(System.Uri)' to 'System.Uri'
Upvotes: 0
Reputation: 15237
The way you have it right now doesn't seem to make sense. moment
is an instance of Moment
, not a list of things (which is what ItemsSource
expects). The list of things is the PhotoFilePath
property on Moment
(which, as an aside, is poorly named since it is a collection, not a single path).
I'm assuming what you really want to do is bind ItemsSource
to moment.PhotoFilePath
:
ItemsSource="{x:Bind moment.PhotoFilePath}">
You'll need to change your DataTemplate to just target a Uri:
<DataTemplate x:DataType="Uri">
Note that I am not positive if you can just say "Uri" there. I don't have a UWP project in front of me.
and then UriSource to each item inside of that property:
<BitmapImage UriSource="{x:Bind}" />
Upvotes: 2