Select to view content in your preferred language

I'll complaint for the wpf binding programming style

3536
5
03-30-2011 08:31 PM
yyz
by
Emerging Contributor
I am a new comer to WPF programming, And I am using the esri silverlight/WPF api to develop some GIS app based on Arc Server service. The esri helper give many  helps to the sivlerlight/WPF api and many demos. but the major in helps are achieved by staitic binding in wpf xaml. This is great when just need some simple and single task. But when I need to develop some complex functions, I need to combine several simple tool. but How can I do it in code  behind ? For example active editor's select or add commant for the map control, or change the location of a feature in the featurelayer throug code, or May I need to change the feature attributes with code .
But so far, I donnt find a theme about these.
Should any body help me .

Thx so much!  Appreciations!
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
I think you are talking about this:
        <Grid.Resources>
            <esri:Editor x:Key="MyEditor" 
                         Map="{Binding ElementName=MyMap}" 
                         LayerIDs="ThreatAreas"
                         GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"                          
                             />
        </Grid.Resources>


You are right. WPF does not like this binding statement under resources.
In WPF, you can delete the line in red and set its Map property in code-behind:
Editor editor = this.LayoutRoot.Resources["MyEditor"] as Editor;
editor.Map = this.MyMap;


This is related thread: http://forums.arcgis.com/threads/26130-WPF-vs-Silverlight
0 Kudos
yyz
by
Emerging Contributor
I think you are talking about this: 
        <Grid.Resources>
            <esri:Editor x:Key="MyEditor" 
                         Map="{Binding ElementName=MyMap}" 
                         LayerIDs="ThreatAreas"
                         GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"                          
                             />
        </Grid.Resources>


You are right. WPF does not like this binding statement under resources. 
In WPF, you can delete the line in red and set its Map property in code-behind: 
Editor editor = this.LayoutRoot.Resources["MyEditor"] as Editor;
editor.Map = this.MyMap;


This is related thread:   http://forums.arcgis.com/threads/26130-WPF-vs-Silverlight


Thanks for your reply. But it is not just that .I want to do more. For example:
I obtain one Feature from the FeatureLayer T2 by Selecting. Then I want to change its location
and attributes. But it can not work. the codes were run, but when I update(refresh) the map,
the location have not changed.
Would you please give some advance about this. Thanks again.
Graphic g = T2.SelectedGraphics.ToList()[0];
MapPoint mp = g.Geometry as MapPoint;
Console.WriteLine("description: {0}", g.Attributes["description"]);
Console.WriteLine("x: {0}, y: {1}", mp.X, mp.Y);
mp.X = mp.X + 100;
mp.Y = mp.Y + 50;
g.Attributes["description"] = "y23z";
T2.SaveEdits();
//T2.Update();
0 Kudos
yyz
by
Emerging Contributor
Thanks for your reply. But it is not just that .I want to do more. For example:
I obtain one Feature from the FeatureLayer T2 by Selecting. Then I want to change its location
and attributes. But it can not work. the codes were run, but when I update(refresh) the map,
the location have not changed.
Would you please give some advance about this. Thanks again.
                Graphic g = T2.SelectedGraphics.ToList()[0];
                MapPoint mp = g.Geometry as MapPoint;
                Console.WriteLine("description: {0}", g.Attributes["description"]);
                Console.WriteLine("x: {0}, y: {1}", mp.X, mp.Y);
                mp.X = mp.X + 100;
                mp.Y = mp.Y + 50;
                g.Attributes["description"] = "y23z";
                T2.SaveEdits();
                //T2.Update();


The above code can work correct now .
And now I want to know how to active select command or editVerticles command or others for map ?
I can not achieve that fome code-behind.
Should anybody help me? Thx a lot.
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos
yyz
by
Emerging Contributor
This is related thread: http://forums.arcgis.com/threads/24340-About-Editor_EditCompleted-...


Your replies give me inpiration to solve the problem. Appreciations. And wish you happiness in you work :`)
0 Kudos