Select to view content in your preferred language

How to binding mainpage's map?

2359
16
10-27-2010 05:54 AM
ShaningYu
Honored Contributor
Title should be How to bind to MainPage's map?
---------------------------------

This is the continuation of the thread: http://forums.arcgis.com/threads/15556-ClosedFacility?p=49147#post49147.  The scenario is described below:
1) Create a UserControls file by loading the ClosedFacility component from ESRI: http://help.arcgis.com/en/webapi/sil...losestFacility
2) In the usercontrol xaml, I defined
            <esri:Map x:Name="_Map" Background="White" Extent="-117.23,34.03,-117.16,34.08" >
3) Add some code in MainPage.xaml and MainPage.xaml.cs to load the ClosedFacility dialog when it is needed. Also set this component's _Map is set to the same as the parent's map.
Results obtained:  All of the buttons are disabled.

I reported this incident.  ESRI's Jennifer responded me that:
"All the buttons have Command binding which can only be resolved if their DataContext is resolved. In this sample, each button's DataContext is set to an Editor which is part of Resources. Each of these editors has their Map property bound to a map, using Element binding.
Since you are moving this to a different UserControl that does not contain your map, Element binding will not work. You need to resort to other means of binding. Maybe create your own DependencyProperty (Map) in the UserControl so that you can use this instead. "

Per her advise, I revised the code (only 1 line here) in the usercontrol's xaml:
                <esri:Editor x:Key="MyBarriersEditor" LayerIDs="MyBarriersGraphicsLayer"
                         Map="{Binding ElementName=_Map}" />
to:
                <esri:Editor x:Key="MyBarriersEditor" LayerIDs="MyBarriersGraphicsLayer"
                         Map="{Binding ElementName=MainPage.MyMap}" />
But it still does not work.  I believe that the binding is not right.  It is somehow chanllege for me and I have very limited experience on it.  Do you know how to bind the usercontrol's map to the MainPage's map?  Thanks.
0 Kudos
16 Replies
ShaningYu
Honored Contributor
After the removal of
Map="{Binding ElementName=MyMap}
The problem is still unsolved.
0 Kudos
JenniferNery
Esri Regular Contributor
Kindly see the attached sample. Maybe you can compare what you have done different and then maybe see why this sample works.
0 Kudos
ShaningYu
Honored Contributor
One of the problem is I am still not sure how to effectively bind to the MainPage's map.  I will try your sample code next week.
Thanks and have a nice weekend.
0 Kudos
ShaningYu
Honored Contributor
Jennifer:
I tried your code that is essentially the same as the source code in http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ClosestFacility
But the results received are identially - All of the buttons except for the 'Clear All Graphics' are disabled.  I might give up to use if for the time-being.
Thanks for your a lot of time.
Shaning
0 Kudos
JenniferNery
Esri Regular Contributor
I checked the attached solution and it works for me, the buttons are not disabled.  The code is identical from the SDK sample because that is what you were trying to follow, right? The only difference is they reside in different UserControls but the Map DependencyProperty should work.
0 Kudos
XavierBerni
New Contributor
I am investigating a similar problem where the Map DependencyProperty isn't getting set from my UserControl which exists in my custom Silverlight library. Seems like this could be related to Silverlight versions. The following information comes from the msdn link http://msdn.microsoft.com/en-us/library/cc221408(VS.95).aspx.

"Applications targeting Silverlight version 3 can only bind to target properties of a FrameworkElement. Support for binding to any DependencyObject dependency property was added in Silverlight 4."

It does not look like UserControl derives from FrameworkElement. See msdn documentation:

http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement(v=VS.95).aspx#inheritanceCon...

The following link shows someone with a similar problem and the workaround they used.

http://betaforums.silverlight.net/forums/p/182820/418564.aspx
0 Kudos
DominiqueBroux
Esri Frequent Contributor
"Applications targeting Silverlight version 3 can only bind to target properties of a FrameworkElement. Support for binding to any DependencyObject dependency property was added in Silverlight 4."
It does not look like UserControl derives from FrameworkElement. See msdn documentation:
http://msdn.microsoft.com/en-us/libr...tanceContinued

UserControl derives from Control, so derives indirectly from FrameworkElement as well.


The following link shows someone with a similar problem and the workaround they used.

http://betaforums.silverlight.net/fo...20/418564.aspx

I am not sure we are in the same case since Map doesn't derive from ContentControl.
Personally I never experienced any issue when adding a DP of type Map but if you run into this kind of issue please share the code I will try to analyze.
0 Kudos