MainWindow.xaml <Window.Resources> <DataTemplate x:Key="movieImage"> <StackPanel> <Image Stretch="Fill"> <Image.Source> <BitmapImage UriSource="{Binding Images}"/> </Image.Source> </Image> </StackPanel> </DataTemplate> </Window.Resources> <Grid> <!--<TextBlock Text="Choose Movie" FontSize="15"/>--> <StackPanel> <ListBox Width="200" Height="100"> <ListBoxItem> <Image Source="{Binding Images}"></Image> </ListBoxItem> </ListBox> </StackPanel> </Grid>
//MainWindow.xaml.cs public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.move = new Movies(); this.DataContext = this.move; } public Movies move { get; set; } } //Movies.cs public class Movies { public Movies() { define = new Define(); Book(); } public Define define { get; set; } private void Book() { this.define.Movie = new ObservableCollection<MovieModel>(); this.define.Movie.Add(new MovieModel() {Images = new Uri(@"\Terminator.jpg",UriKind.RelativeOrAbsolute) }); } } //MovieModel.cs public class MovieModel { public string MovieName { get; set; } public Uri Images { get; set; } } //Define.cs public class Define { public ObservableCollection<MovieModel> Movie { get; set; } public ObservableCollection<Theaters> Theater { get; set; } }
this.move = new Movies(); this.DataContext = this.move; // you're assigning newly referenced object as DataContext, which hasn't any value
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)