Как получить объект canvas

<ItemsControl ItemsSource="{Binding Shapes}">
     <ItemsControl.ItemTemplate>
         <DataTemplate>
             <Ellipse
                 Width="30"
                 Height="30"
                 Fill="{Binding Fill}" />
         </DataTemplate>
     </ItemsControl.ItemTemplate>
     <ItemsControl.ItemsPanel>
         <ItemsPanelTemplate>
             <Canvas Name="canvas1"/>
         </ItemsPanelTemplate>
     </ItemsControl.ItemsPanel>
     <ItemsControl.ItemContainerStyle>
         <Style TargetType="ContentPresenter">
             <Setter Property="Canvas.Left" Value="{Binding X}" />
             <Setter Property="Canvas.Top" Value="{Binding Y}" />
         </Style>
     </ItemsControl.ItemContainerStyle>
 </ItemsControl>

В этом коде xaml вывожу все объекты Shapes на Canvas, но не могу получить ссылку на Canvas с именем canvas1 в коде C#


Ответы (1 шт):

Автор решения: thebrokenblow
private void LoadedCanvas(object sender, RoutedEventArgs e)
{
    Canvas = (Canvas)sender;
}

<Canvas Loaded="LoadedCanvas" Cursor="{Binding Cursor}" Focusable="True"
ClipToBounds="True" IsItemsHost="True"/>
→ Ссылка