As like the subject, I want to add WPF controls of the same template but different data inside as many as I want dynamically.
As you can see in the picture, the control that I want to duplicate is somewhat complicated. The overall control is wrapped inside Canvas
inside ScrollViewer
.
Each StackPanel
wraps TextBlock
and another
Canvas Control and this StackPanel
is what I want to reproduce.
It is coded like:
<ScrollViewer x:Name="ScrollBoard" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Canvas x:Name="CanvasBoard" VerticalAlignment="Center" HorizontalAlignment="Center" Width="200" Height="250" Background="Gray">
<StackPanel x:Name="CanvasStack" Background="DimGray">
<CheckBox />
<Border x:Name="CanvasBorder" BorderBrush="Black" BorderThickness="1">
<Canvas Width="150" Height="200" ClipToBounds="True">
<Image x:Name="CanvasImage" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Source="C:\test.jpg"/>
</Canvas>
</Border>
<TextBlock Text="Test.jpg" />
</StackPanel>
</Canvas>
</ScrollViewer>
I want to duplicate that CanvasStack StackPanel
control inside CanvasBoard Canvas
Control.
Of course, not just duplicate but also want to take control of that.
For example, change the position, edit TextBlock
text, replace Image
and get Click event and so on.
Plus, I will not use ListBox
or ListView
for it because each Control should be located in absolute x,y coordination with various size.
There are some examples doing similar things like 'adding a button to certain control'. But what I found were just add control in backend with hard-coded properties which may not fit for this kind of complex control.
Thank you in advance.