我得到了以下矩形如何在mvvm的矩形命令上使用多重绑定?
<Rectangle
Width="{Binding Width}"
Height="{Binding Length}"
Tag="{Binding Id}"
Name="rectangleDrawnMachine">
<i:Interaction.Triggers>
<i:EventTrigger
EventName="MouseDown">
<cmd:EventToCommand
Command="{Binding Main.UpdateSelectedMachine, Mode=OneWay, Source={StaticResource Locator}}"
PassEventArgsToCommand="True"
CommandParameter="{Binding ElementName=rectangleDrawnMachine}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Rectangle>
该矩形被绑定到其在一个以上的ItemsControl声明的模型。该文件结构是如下所示:
<Grid>
<ItemsControl ItemsSource="{Binding AllMachines}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Name="canvasDrawnMachines" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Rectangle Name="rectangleDrawnMachine"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
现在我UpdateSelectedMachine -command需要矩形的至少三个属性:
- 位置X
- 位置Y
- ID /标签
使用CommandParameter o如果矩形本身,我的命令会得到很多关于矩形的信息(比如需要的标签)。但它没有获得关于画布的(X-& Y-)位置的必要信息。
所以我的问题是:如何在我的矩形命令上使用多重绑定?以及如何转移画布的位置?
谢谢您的回答。多重绑定方式工作得很好。问题是画布的矩形位置不能传递正确的值。它说'没有定义'。也许是因为我的数据模板有多个矩形? – Chpo7234
这不是多个矩形的问题。你可以尽可能多地拥有它。我已经更新了答案中的绑定。 – Parag
感谢您的更新。问题例如Canvas.Top返回我{DependencyProperty.UnsetValue}。代码' '没有问题 –
Chpo7234