I want to develop a kind of Vector Image Editor using WPF. Every shape with the same form is placed in an ItemsControl. There are at least 4 kind of shapes (line, rectangle, bitmap etc). The problem is:
I cannot click the shape from layer below the other layer.
The requirement:
- ItemsControl ItemsPanelTemplate must be Canvas with size cannot be 0.
- Every shape can be click anytime without activate IsHitTestVisible at the clickable shape.
The questions:
How can I enable to click shape below other shape in upper ItemsControl?
Edit 1: Add code snippet
<Grid>
<!--Array of Ellipses-->
<ItemsControl ItemsSource="{Binding EllipseSource}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Path=Distance}" />
<Setter Property="Canvas.Width" Value="10" />
<Setter Property="Canvas.Top" Value="{Binding Path=Top}" />
<Setter Property="Canvas.Height" Value="10" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<Ellipse MouseDown="EllipseOnMouseDown" />
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--Array of Rectangles-->
<ItemsControl ItemsSource="{Binding RectangleSource}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Path=Distance}" />
<Setter Property="Canvas.Width" Value="10" />
<Setter Property="Canvas.Top" Value="{Binding Path=Top}" />
<Setter Property="Canvas.Height" Value="10" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<Rectangle MouseDown="RectangleOnMouseDown" />
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Panel.ZIndex
Attached Property MSDN – GopichandarPanel.ZIndex
change how a shape hide other shapes, which is overlap each other. – Tuyen PhamZIndex
dynamic based on the events. – Gopichandar