Hello,
I'm working on a ListBox that overrides its' ItemsPanelTemplate to use a Canvas instead of a StackPanel. ListBoxItems have a DataTemplate that uses a converter to define the look and position of each ListBoxItem on the canvas. When I add an item to the collection that the ListBox is bound to, I'd like to be able to add other UIElements to the canvas. Can I accomplish this outside of the ListBoxItem's converter?
my resources section is like this:
<Style TargetType="ListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Canvas x:Key="cnvAwesome">
</Canvas>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListBoxItem">
<Setter Property="Canvas.Left" Value="{Binding Path=Position.X}" />
<Setter Property="Canvas.Top" Value="{Binding Path=Position.Y}" />
</Style>
And a ListBox:
<ListBox x:Name="lstAwesome" ItemsSource="{Binding Source={StaticResource someCollection}}"/>
And the collection that the ListBox is bound to:
public ObservableCollection<SomeType> someCollection {get; set; }
So, if I have a method to add an item to the collection someCollection that the ListBox lstAwesome is bound to:
private void AddItemToDataboundCollection(SomeType someItem)
{
someCollection.Add(someItem)
// I'd like to add a UIElement to the canvas that the ListBox uses to layout items here.
}
So, can I add UIElements to a canvas being used for an ItemsPanel by a databound listbox? Programmatically, when I'm adding items to the collection that that ListBox is bound to?
I'd greatly appreciate any input!