내 컬렉션을 보유하려면 ItemsControl
을 사용하고 있습니다. ItemsPanel
는 ItemTemplate
내가 블록 (내 컬렉션의 항목)에 클릭을 잡으려고 DataTemplate
의 명령을 바인딩 할 Border
>StackPanel
>TextBlocks
의 블록하는 Canvas
입니다DataTemplate에서 WPF 명령 바인딩
코드 :
<Grid Grid.Row="1" Grid.Column="1" >
<ItemsControl ItemsSource="{Binding Products}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<helpers:DragCanvas
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AllowDragging="True"
AllowDragOutOfView="False" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- The border and its content is what I see
on my canvas, I want to bind a command here (on click do something) -->
<Border BorderThickness="1" BorderBrush="Gold">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=Price}" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
한 입력에 대한을의'명령에 대한 -1 = "{SomeCommand 바인딩} ''이 DataTemplate을의 DataContext에이 제품으로 설정됩니다 (모델) ViewModel이 아닌 – AymenDaoudi
충분히 정교합니다. 편집 됨. – Den