私は矩形が上記のItemsControlに宣言されているモデルにバインドされている以下の長方形mvvmのrectangle-commandにmultibindingを使用する方法は?
<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>
を得ました。矩形の少なくとも3つの特性を必要と-command
<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:
- 位置X
- 位置y
- ID /ドキュメント構造は、次のようなものですタグ
CommandParameter o f矩形そのものmyコマンドは、必要なタグのような長方形に関する多くの情報を取得します。しかし、それはキャンバスの(X-& Y-)位置についての必要な情報を得ることはありません。
私の質問は、どのように私の矩形コマンドにマルチバインディングを使用するのですか?どのようにキャンバスの位置を移すか?
ありがとうございます。マルチバインディング方法は本当にうまく動作します。問題はキャンバスの四角形の位置が正しい値を転送しないことです。それは「定義されていない」と言います。多分私のデータ・テンプレートのために複数の矩形があるからでしょうか? – Chpo7234
複数の矩形では問題ありません。あなたはあなたが好きなだけ多くを持つことができます。私は答えのバインディングを更新しました。 – Parag
ありがとうございます。例: Canvas.Topは{DependencyProperty.UnsetValue}を返します。コード ' は問題なく動作します –
Chpo7234