My WPF application has a listbox with multiple items. On each item, we have an image and a textbox.
See XAML below:
<ListBox x:Name="lstMagic" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="10,200,10,0" Width="Auto" Height="558" Background="{x:Null}" BorderBrush="Transparent">
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="images/plates/pig.jpg" Margin="0,0,5,0" Width="72"/>
<TextBox IsReadOnly="True" Background="{x:Null}" Foreground="White" Width="912">Some Magic is going to happen</TextBox>
</StackPanel>
</ListBoxItem>
So the list begins with the pigs as expected. IN front of the pig, he loads the pig.jpg sucessfully.
Beside that form section, I have a button. I was able to do some magic on that button to add a new listBoxItem.
private void btnDoMagic(object sender, RoutedEventArgs e)
{
ListBoxItem newMagic = new ListBoxItem();
Image imageCurrent = new Image();
imageCurrent.Source = new BitmapImage(new Uri("images/plates/someOtherImage.jpg", UriKind.RelativeOrAbsolute));
newMagic.Content = imageCurrent;
lstCardapio.Items.Add(newMagic);
}
}
This function works, and adds the image successfully to the list! But I have some questions: How can I make just like my first XAML? An image and a textbox? How can I add these at my button event?
I will need this done because we will get these items from our database, so we must load these dynamically.