Du kannst entweder ein UserControl definieren, welches dann ein composite aus TextBlock + deinem Canvas ist, oder was viel flexibler sein wird, ein eigenes Control machen.
Dann hast du also ein Control und in diesem dann dein Canvas und Textblock.
Du erbst also von ItemsControl, und im Constructor setzt du im Code setzt du ein Template auf.
Als Beispiel hier das Template von dem GMaps Map Control:
XML-Daten
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
| <ItemsControl Name="figures"> <ItemsControl.ItemTemplate> <DataTemplate> <ContentPresenter Content="{Binding Path=Shape}" /> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Canvas.Left" Value="{Binding Path=LocalPositionX}"/> <Setter Property="Canvas.Top" Value="{Binding Path=LocalPositionY}"/> </Style> </ItemsControl.ItemContainerStyle> </ItemsControl> |