Thread View: alt.pl.comp.lang.csharp
1 messages
1 total messages
Started by Paweł
Mon, 22 Oct 2012 12:44
Kolekcja obrazków w listbox w WPF
Author: Paweł
Date: Mon, 22 Oct 2012 12:44
Date: Mon, 22 Oct 2012 12:44
55 lines
2732 bytes
2732 bytes
Witam
Chciałbym móc wczytywać obrazki do kontrolki listbox za pomocą kontrolki
opendialogfile, jednak zamiast obrazka pokazuje mi się ścieżka do pliku.
Co zrobić aby w listbox uzyskać listę obrazków ?
Definicja listboxa w kodzie XAML wygląda tak:
<ListBox Cursor="Hand" Height="350" Margin="5,0,0,0"
Name="listaFotek_Lb" DataContext="{Binding}">
<ListBox.Resources>
<Style TargetType="{x:Type Image}">
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="100" />
<!--<EventSetter Event="MosueLeftButtonDown"
Handler="DragImage" />-->
</Style>
</ListBox.Resources>
</ListBox>
a kod obsługujący kliknięcie tak:
private void Btn_WczytajFotki_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new
Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".jpg";
dlg.Filter = "JPG Files (*.jpg)|*.jpg|JPEG files
(*.jpeg)|*.jpeg|BMP Files (*.bmp)|*.bmp";
dlg.Multiselect = true;
Nullable<bool> result = dlg.ShowDialog();
if (result==true)
{
if (dlg.FileNames != null)
{
this.listaFotek_Lb.Items.Clear();
for (int i = 0; i < dlg.FileNames.Length; i++)
{
listaFotek_Lb.Items.Add(new BitmapImage(new
Uri(dlg.FileName, UriKind.Absolute)));
}
}
}
}
Jak ten kod poprawić aby w listboxie wyświetlały się obrazki ?
Z góry dzięki i pozdrawiam Paweł
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads