Binding to Selected Feature

830
3
06-21-2013 12:57 PM
Labels (1)
KeithGemeinhart
Occasional Contributor
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.
0 Kudos
3 Replies
BrianLocke
Occasional Contributor II
I would take a look at Jeff Jacksons work on GitHUB especially his MVVM patterns work,  his presentations are extremely beneficial
0 Kudos
KeithGemeinhart
Occasional Contributor
Thanks for the response. I am familiar with Jeff's examples. He had a great presentation at Dev Summit this year. However, I'm pretty sure his example binds a list of results to a layer's graphics collection. So it goes ViewModel --> Map.

I'm looking for a way to bind the layer's selected feature. So ... Map --> ViewModel.

I will revisit his code to make sure I'm not missing anything.
0 Kudos
AnttiKajanus1
Occasional Contributor III
Hi there,

I have done blog posts about things that more or less uses this approach. Sorry already for for linking to external site instead of describing solution here.

Check if this helps you http://kajanus.net/?p=342, even thou it is done with Windows Store SDK. Just bind the selected graphic to your control and you should be ready to go. If you want, I might write more detailed blog post for WPF.

For WPF you can use also DataContextProxy from this post http://kajanus.net/?p=15

T
here might be also one interesting post releated to this issue, or actually visualizing the selected item in here : http://kajanus.net/?p=132 (it seems that I have forgot to publish the GitHub for this example, I try to remember to do that later)
0 Kudos