Given a ArcGISLocalFeatureLayer as a layer on the WPF runtime map object, how can I bind a ViewModel to the selected feature or graphic?
<esri:ArcGISLocalFeatureLayer x:Name="MySampleLayer" ID="MyFeatures"
Path="C:/..../Samples.mpk" LayerName="MyFeatures" OutFields="*" DisableClientCaching="True"
Editable="True" AutoSave="False" ValidateEdits="True"
Mode="OnDemand" SelectionColor="#FFFFFF00" />
I realize there is already a FeatureDataGrid and FeatureDataForm in the runtime, but I'm trying to achieve a little different user experience. For simplicity, suppose I just have some controls on the same window as the map:
<Grid >
<StackPanel>
<StackPanel.DataContext>
<local:FeaturePropertiesViewModel/>
</StackPanel.DataContext>
<TextBox Text="{Binding FeatureName}" />
<TextBox Text="{Binding FeatureInfo}" />
</StackPanel>
</Grid>
and a simple ViewModel ...
class FeaturePropertiesViewModel
{
public string FeatureName { get; set; }
public string FeatureInfo { get; set; }
public Graphic SelectedFeature { get; set; } // ??? use this somehow?
public GraphicCollection AllGraphics { get; set; } // ??? use this somehow?
}
How do I get those text fields updated to when a new feature is selected? Ideally, I'd like two-way binding so that changing the text updates the underlying feature class.
Update: Based on Darlene's suggestion, I started looking into other ways to get the information include the mouse interactions - since that is how the feature is being selected.
I can capture/handle the MouseLeftButtonDown event and do everything I need to in the code-behind. So I started working of that to refactor to MVVM. Using MvvmLight, I can map that event to a command like this:
<esri:ArcGISLocalFeatureLayer ... />
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<cmd:EventToCommand Command="{Binding Path=MyLeftMouseCommand,
Source={StaticResource MyVieModel}}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=esriLocal:ArcGISLocalFeatureLayer}}"
PassEventArgsToCommand="False" />
</i:EventTrigger>
</i:Interaction.Triggers>
</esriLocal:ArcGISLocalFeatureLayer>
However, I need both the mouse event args (GraphicMouseButtonEventArgs) and the selected graphic. And I'm having trouble getting both passed to a command. I tried RelayCommand like this ...
public RelayCommand<ArcGISLocalFeatureLayer> MyLeftMouseCommand{ get; protected set; }
In constructor ...
MyLeftMouseCommand= new RelayCommand<ArcGISLocalFeatureLayer>(p =>
{
Console.Writeline("It works!");
});
And that will get me the CommandParameter value if I set PassEventArgsToCommand="False", or I can get GraphicMouseButtonEventArgs if I set PassEventArgsToCommand="True", but I can't get them at the same time!
Also using ReactiveUI if there is anything in there that might be helpful.