Vraagje,
Vanuit C# WPF bouw ik dynamische listbox controls (hiervoor gebruik ik dus geen XAML).
Tijdens het aanmaken van de Listboxen, voeg ik ListBoxItems toe aan het Listboxen.
Naderhand wil ik, als ik op een ListBoxItem click, de text van de ListBoxItem doorsturen en van de ListBox waaronder de ListBoxItem valt.
Hoe kan ik dit doen?
Code tot nu toe:
ListBox iListBox;
ListBoxItem iListBoxItem;
string[] ListBoxes = new string[] {"ListBox1","ListBox2"};
string[] ListBoxItem = new string[] { "ListBoxItem1", "ListBoxItem2", "ListBoxItem3" };
foreach(string box in ListBoxes)
{
iListBox = new ListBox();
iListBox.Name = box;
foreach (string item in ListBoxItem)
{
iListBoxItem = new ListBoxItem();
iListBoxItem.Content = item;
iListBoxItem.Selected += ListBoxItem_Do(box, item);
iListBox.Items.Add(iListBoxItem);
}
LeftPanel.Children.Add(iListBox);
}
// Geeft de melding: Cannot implicitly convert type 'void' to 'System.Windows.RoutedEventHandler’
public void ListBoxItem_Do(string test, string test2)
{
MessageBox.Show(test);
}
Vanuit C# WPF bouw ik dynamische listbox controls (hiervoor gebruik ik dus geen XAML).
Tijdens het aanmaken van de Listboxen, voeg ik ListBoxItems toe aan het Listboxen.
Naderhand wil ik, als ik op een ListBoxItem click, de text van de ListBoxItem doorsturen en van de ListBox waaronder de ListBoxItem valt.
Hoe kan ik dit doen?
Code tot nu toe:
ListBox iListBox;
ListBoxItem iListBoxItem;
string[] ListBoxes = new string[] {"ListBox1","ListBox2"};
string[] ListBoxItem = new string[] { "ListBoxItem1", "ListBoxItem2", "ListBoxItem3" };
foreach(string box in ListBoxes)
{
iListBox = new ListBox();
iListBox.Name = box;
foreach (string item in ListBoxItem)
{
iListBoxItem = new ListBoxItem();
iListBoxItem.Content = item;
iListBoxItem.Selected += ListBoxItem_Do(box, item);
iListBox.Items.Add(iListBoxItem);
}
LeftPanel.Children.Add(iListBox);
}
// Geeft de melding: Cannot implicitly convert type 'void' to 'System.Windows.RoutedEventHandler’
public void ListBoxItem_Do(string test, string test2)
{
MessageBox.Show(test);
}
Laatst bewerkt: