の代わりにを使用するようにListBoxオーバーライドするに取り組んでいます。 キャンバス上のそれぞれの外観と位置を定義するコンバーターを使用する があります。がバインドされているコレクションにアイテムを追加するときに、他の をキャンバスに追加できるようにしたいと考えています。のコンバータの外でこれを達成できますか?ItemsPanelTemplateCanvasStackPanelListBoxItemsDataTemplateListBoxItemListBoxUIElementListBoxItem
私のリソースセクションは次のようなものです:
<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>
そしてリストボックス:
<ListBox x:Name="lstAwesome" ItemsSource="{Binding Source={StaticResource someCollection}}"/>
ListBox がバインドされているコレクション:
public ObservableCollection<SomeType> someCollection {get; set; }
したがって、ListBox lstAwesome がバインドされているコレクション someCollection にアイテムを追加するメソッドがある場合:
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.
}
では、データバインドされたリストボックスによって ItemsPanel に使用されているキャンバスに UIElements を追加できますか? そのListBoxがバインドされているコレクションにアイテムを追加するとき、プログラムで?
ご意見をいただければ幸いです。