【发布时间】:2014-07-22 02:47:19
【问题描述】:
我正在使用ItemsControl 来保存我的收藏。
ItemsPanel 是 Canvas,ItemTemplate 是 Border>StackPanel>TextBlocks 的块
我想在DataTemplate 中绑定一个命令来捕捉对块的点击(我的收藏项)
代码:
<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>
【问题讨论】:
标签: wpf mvvm data-binding datatemplate