I have listbox and on click event I open new panel where i change data of listbox, more accurately image source. I have problem how to update listbox to have new picture. Thanks in advance.
Here is my code:
<ListBox x:Name="lbNarudzbe" MouseLeftButtonUp="lbNarudzbe_MouseLeftButtonUp" HorizontalAlignment="Center" MaxHeight="600">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Margin="0,5,0,0" Width="50" Height="50" HorizontalAlignment="Center" Source="{Binding Path=Picture}" />
<TextBlock HorizontalAlignment="Center" FontSize="23" Text="{Binding Path=UkupnaCijena}" Width="80"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
public partial class Page : UserControl
{
ObservableCollection<Narudzba> narudzbe = new ObservableCollection<Narudzba>();
public Page()
{
InitializeComponent();
narudzbe.Add(new Narudzba());
narudzbe.Add(new Narudzba());
narudzbe.Add(new Narudzba());
narudzbe.Add(new Narudzba());
lbNarudzbe.ItemsSource = narudzbe;
}
public class Narudzba
{
//...
public string Picture
{
get { return "picture source"; }
}.....
Best Answer
Basically when you want to update the picture in the listbox, you are updating the Picture property of your Narudzba class, and since your Narudzba class does not implement the INotifyPropertyChanged interface the listbox can't update the picture.
Here's some code that might help.
Then the lbNarudzbe_MouseLeftButtonUp event code should look like this
HTH.