画鋲を MapLayer にデータ バインドしています。それらは正常に表示されますが、relaycommand を使用してマウスの leftbuttonUp からイベント引数を渡すと、オブジェクト ソースは楕円になります。MapPolygon でこのメソッドを使用して、必要な情報をオブジェクトから取得しました。
私はmvvmが初めてなので、これにひどく近づいているかもしれませんので、お知らせください!
これは私のMapPolygonsで機能します(vmはextendedMapPolygonクラスの名前空間を参照します)
<DataTemplate x:Name="polyTemplate">
<vm:extendedMapPolygon cName="{Binding _cName}" Locations="{Binding _Locations}" />
</DataTemplate>
MapLayer の XAML は次のとおりです。
<m:MapItemsControl ItemTemplate="{StaticResource polyTemplate}" ItemsSource="{Binding Path=_PolyforDisplay, Mode=TwoWay}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<cmd:EventToCommand Command="{Binding Path=PolySelCommand}" PassEventArgsToCommand="True" ></cmd:EventToCommand>
</i:EventTrigger>
</i:Interaction.Triggers>
</m:MapItemsControl>
私のviewModelコンストラクターで
PolySelCommand = new RelayCommand<MouseButtonEventArgs>(PolySelCommandExecute);
そして最後に実際のコマンド
public RelayCommand<MouseButtonEventArgs> PolySelCommand { get; set; }
private void PolySelCommandExecute(MouseButtonEventArgs cmp)
{
Polygon poly = cmp.OriginalSource as Polygon;
extendedMapPolygon ePoly = poly.Parent as extendedMapPolygon;
_MapPolygonSelected = ePoly.cName;
}
(私が現在使用している方法と、他の人に役立つことを願って、これをここに置きます!)
ただし、プッシュピンで同じことを試みると、cmp.OriginalSource は楕円であり、他に何も渡されないようです。
私の画鋲コード (このコードでは、MapControl で画鋲を使用しているだけです)
<DataTemplate x:Name="ppTemplate">
<m:Pushpin ToolTipService.ToolTip="{Binding _psName}" Location="{Binding _Location}" />
</DataTemplate>
<m:MapItemsControl ItemTemplate="{StaticResource ppTemplate}" ItemsSource="{Binding Path=_PinsforDisplay, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<cmd:EventToCommand Command="{Binding Path=pinSelCommand}" PassEventArgsToCommand="True" ></cmd:EventToCommand>
</i:EventTrigger>
</i:Interaction.Triggers>
</m:MapItemsControl>
コマンド パラメータを使用する必要がありますか? または、画鋲をクリックしたときにビューモデルにテキストを渡す別の方法です。これが実際に必要です。