Bonjour je desérialise des éléments json grace à la conversion jsontocsharp.com.
j'ai les classes suivante:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public class MovieSearch
{
public object score { get; set; }
public int popularity { get; set; }
public bool translated { get; set; }
public bool adult { get; set; }
public string language { get; set; }
public string original_name { get; set; }
public string name { get; set; }
public string alternative_name { get; set; }
public string movie_type { get; set; }
public string id { get; set; }
public string imdb_id { get; set; }
public string url { get; set; }
public int votes { get; set; }
public double rating { get; set; }
public string certification { get; set; }
public string overview { get; set; }
public string released { get; set; }
public List<object> posters { get; set; }
public List<object> backdrops { get; set; }
public int version { get; set; }
public string last_modified_at { get; set; }
}
public class RootObjectsearch
{
public string exec_time { get; set; }
public List<MovieSearch> movies { get; set; }
} |
je cherche à binder l'élément suivant dans une images d'un Template d'une listbox que j'alimente avec itemsource.
1 2
| var root = JsonConvert.DeserializeObject<RootObjectsearch>(e.Result);
seeensearch.ItemsSource = root.movies |
Tout vas bien sauf pour l'objet:
public List<object> posters { get; set; }
j'ai binder l'image de la façon suivante mais ma methode semble incorrecte:
1 2 3 4 5 6 7 8 9 10 11
| <ListBox x:Name="seeensearch" HorizontalAlignment="Left" Width="416" Height="414" SelectionChanged="searchdetails_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="400" Height="150">
<Image x:Name="tpicfilmline" Source="{Binding posters[1].url}" RenderTransformOrigin="0.5,0.5" Height="110" Width="90" Margin="0,-78,0,0"/>
<TextBlock x:Name="ttitleline" Height="43" Text="{Binding name}" Margin="100,-35,0,0"/>
<TextBlock x:Name="trelease" Text="{Binding released}" Height="46" HorizontalAlignment="Left" Width="266"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox> |
je me retrouve avec l'erreur suivante:
1 2 3 4 5 6 7 8 9 10
| System.Windows.Data Error: BindingExpression path error: 'url' property not found on '{
"image": {
"type": "poster",
"size": "w154",
"height": 250,
"width": 154,
"url": "http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w154/8I62x8uGDexcC7Kuj0jhfwGEEm6.jpg",
"id": "4fa7d3e119c2956d170026cb"
}
}' 'Newtonsoft.Json.Linq.JObject' (HashCode=47702931). BindingExpression: Path='posters[1].url' DataItem='Myseeen.MovieSearch' (HashCode=26019245); target element is 'System.Windows.Controls.Image' (Name='tpicfilmline'); target property is 'Source' (type 'System.Windows.Media.ImageSource').. |
Comment puis-je m'y prendre?
merci
Partager