I've looked at a few answers on this topic, but I still don't understand. How do I bind from different ObservableCollection collections to each canvas in ContentTemplate?
<TabControl x:Name="Drawing_TabControl"
Grid.Row="0"
Background="WhiteSmoke"
SelectionChanged="Drawing_TabControl_SelectionChanged"
ItemsSource="{Binding New_File_Models}"
SelectedItem="{Binding Selected_File_Model}">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
Background="Transparent">
<TextBlock Text="{Binding Path=Header}" Background="Transparent" />
<Button Height="18"
Width="18"
Background="Transparent"
BorderBrush="Transparent"
Click="Close_TabItem"
Visibility="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=TabItem},
Converter={StaticResource B2V}}">
<Image Source="icons\close_x.png"/>
</Button>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<Grid Background="WhiteSmoke">
<Canvas x:Name="a"
Background="GhostWhite"
Height="6cm"
Width="16cm"
HorizontalAlignment="Center"
VerticalAlignment="Center">
</Canvas>
<Canvas x:Name="b"
Background="Transparent"
Height="6cm"
Width="16cm"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SizeChanged="gridCanvas_SizeChanged"></Canvas>
<Border BorderBrush="Black"
BorderThickness="0.5 0.5 0.5 0.5"
Height="4cm"
Width="14cm"
HorizontalAlignment="Center"
VerticalAlignment="Center"></Border>
<Canvas x:Name="c"
Background="White"
Height="4cm"
Width="14cm"
HorizontalAlignment="Center"
VerticalAlignment="Center"></Canvas>
<Canvas x:Name="d"
Background="Transparent"
Height="4cm"
Width="14cm"
HorizontalAlignment="Center"
VerticalAlignment="Center"></Canvas>
<Canvas x:Name="e"
Background="Transparent"
Height="4cm"
Width="14cm"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ClipToBounds="True"></Canvas>
</Grid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
The task is as follows:
1.Various geometric shapes (Ellipse, Line, Rectangle, etc.) are drawn On the Canvas x:Name="e". This data will be saved to a file.
2. the Other canvases are auxiliary for drawing static data such as markup, grid, etc., they will not be saved to a file.
After studying the answer about nested observablecollection one in another, I became much clearer how to implement this in my case. First, I reworked the XAML markup, replacing
canvaswithlistbox:Next I created a data model:
class Ellipse_M :
class Line_M :
class Rectangle_M :
class Figure_M :
class File_M :
ViewModel:
In order to be able to choose which shape to place at the moment, I created the FigureTemplateSelector :
The other canvases are auxiliary, so I think we should do the same and create a collection inside the
Figureclass.