Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad images to listbox through dialog.Trouble with binding
    primarykey
    data
    text
    <p>I should load images to listbox.I have a trouble when I choose images, to listbox added only border without nothing and only one, I have debuged my code and in collection 6 bitmap images, but loaded only 1 border. 1.That is my class Album:</p> <pre><code> public class Album : INotifyPropertyChanged { private string name; public string Name { get { return name; } set { name = value; OnPropertyChanged(new PropertyChangedEventArgs("Name")); } } private string description; public string Description { get { return description; } set { description = value; OnPropertyChanged(new PropertyChangedEventArgs("Description")); } } private List&lt;BitmapImage&gt; images; public List&lt;BitmapImage&gt; Images { get { return images; } set { images = value; OnPropertyChanged(new PropertyChangedEventArgs("Images")); } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) PropertyChanged(this, e); } public Album() { } public Album(string name, string description, List&lt;BitmapImage&gt; files) { Name = name; Description = description; Images = files; } } </code></pre> <p>2.That my code for child window.When i push button create, I write name, description, and add some photos(please check my method for add is it correct).</p> <pre><code>public partial class DialogCreate : ChildWindow { private List&lt;BitmapImage&gt; temps = new List&lt;BitmapImage&gt;(); private string tempName; private string tempDescription; public List&lt;BitmapImage&gt; Temps { get { return temps; } set { temps = value; } } public string TempName { get { return tempName; } set { tempName = value; } } public string TempDescription { get { return tempDescription; } set { tempDescription = value; } } private OpenFileDialog addPhoto; public DialogCreate() { InitializeComponent(); addPhoto = new OpenFileDialog(); addPhoto.Multiselect = true; addPhoto.Filter = "Image files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"; } private void OKButton_Click(object sender, RoutedEventArgs e) { tempName = txtGetName.Text; tempDescription = txtGetDescription.Text; this.DialogResult = true; } private void CancelButton_Click(object sender, RoutedEventArgs e) { this.DialogResult = false; } private void AddButton_Click(object sender, RoutedEventArgs e) { bool result = (bool)addPhoto.ShowDialog(); if (!result) return; IEnumerable&lt;FileInfo&gt; file = addPhoto.Files; foreach (FileInfo files in file) { Stream s = files.OpenRead(); BitmapImage i = new BitmapImage(); i.SetSource(s); temps.Add(i); } } } </code></pre> <p>3.After that I return to:</p> <pre><code>private void CreateButton_Click(object sender, RoutedEventArgs e) { dialogAlbum = new DialogCreate(); dialogAlbum.Show(); dialogAlbum.Closed += delegate { albums.Add(new Album(dialogAlbum.TempName, dialogAlbum.TempDescription, dialogAlbum.Temps)); AlbumScroll.ItemsSource = albums; lsPhoto.ItemsSource = albums; }; } </code></pre> <p>4.That my xaml:</p> <pre><code>&lt;ListBox Style="{StaticResource ListBoxStyle}" ItemsSource="{Binding Images}" Margin="121,38,171,23" x:Name="lsPhoto" Grid.Column="1" Grid.Row="2" Height="144" Width="600"&gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;StackPanel Orientation="Horizontal"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Border Width="100" Height="100"&gt; &lt;Image x:Name="listPhotos" Source="{Binding}" Width="Auto" Height="Auto"/&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>Please help me, what I did wrong?Or give your advertise.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload