Select to view content in your preferred language

Problems binding URL

529
2
05-01-2012 04:59 AM
KåreRasmussen
Emerging Contributor
Hi everybody.

I´ve downloaded the "FrostedTabs" Silverlight example and Im trying to set the URL thru binding:
<esri:ArcGISDynamicMapServiceLayer  ID="Aflob" Initialized="ArcGISTiledMapServiceLayer_Initialized"
                                                           Url="{Binding Path=SetupModel.LayersUrl}" />

The SetupModel is init thru the main method of the silverlight app:
        public MainPage()
        {
            InitializeComponent();
            MainPageViewModel mainPageViewModel = new MainPageViewModel(); //Here the SetupModel property is initialized
            LayoutRoot.DataContext = mainPageViewModel;

The LayersUrl property looks like this
        private SetupModel setupModel;
        public SetupModel SetupModel
        {
            get
            {
                if (setupModel == null)
                {
                    setupModel = new SetupModel();
                    setupModel.LayersUrl = "http://localhost/ArcGIS/rest/services/aflob/MapServer";
                    setupModel.OverViewMapUrl= "http://localhost/ArcGIS/rest/services/aflob/MapServer";
                    OnPropertyChanged("SetupModel");
                }
                return setupModel;
            }
            set
            {
                if(setupModel!=value)
                {
                    setupModel = value;
                    OnPropertyChanged("SetupModel");
                }
            }
        }

But when the page is loaded, an error like this occurs:
SCRIPT5022: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.ArgumentNullException: 'Url' is not set.
Parameternavn: Url
   på ESRI.ArcGIS.Client.Layer.OnInitializationFailed(EventArgs e)
   på ESRI.ArcGIS.Client.Layer.Initialize()
   på ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer.Initialize()
   på ESRI.ArcGIS.Client.Map.OnApplyTemplate()
   på System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)

If I replace the Binding with this:
<esri:ArcGISDynamicMapServiceLayer  ID="Aflob" Initialized="ArcGISTiledMapServiceLayer_Initialized"
                                                           Url="http://localhost/ArcGIS/rest/services/aflob/MapServer" />
Everything works great.
Why is that?

Any suggestions/comments are greatly appreciated

/Kaare
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
0 Kudos
dotMorten_esri
Esri Notable Contributor
Unfortunately because 'Layer' is not a FrameworkElement, it doesn't have a DataContext, and therefore Binding wouldn't work.
If you have your datacontext defined in your viewmodel which is exposed as a static resource, you can however bind to static resources.
ex: Url="{Binding Source={StaticResource myViewModel}, Path=MyLayerVM.Url}"
0 Kudos