SL4 Breaks ESRI Behaviors

974
13
04-26-2010 12:01 PM
PatrickBrooke
New Contributor II
Hello all,

Unless it is just me, which i sincerely hope it is, SL4 breaks the Measure Action and Constrained Extent Behavior. I will attach my constrained extent behavior code, but it is the same as the ESRI sample, a pretty basic feature. The same code works just great in SL3. Strange Error. Measure Action is much the same. I realize the ESRI tools for SL are developed on SL3, but am hoping to push my new site out in the next week or 2 in SL4. Mainly upgrading for the print functionality. Worth it!

The error message:

"A value type of 'ConstrainExtentBehavior' cannot be added to a collection or dictionary of type 'BehaviorCollection'"

Code:

xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors"

<i:Interaction.Behaviors>
                <esriBehaviors:ConstrainExtentBehavior ConstrainedExtent="-120,30,-60,60" />
  </i:Interaction.Behaviors>
0 Kudos
13 Replies
hcgis
by
New Contributor III
hi patrickbrooke
I had the same problem as yours and i implemented  it with code (insert this snippet in loaded event) and it works (I don't know why???)

System.Windows.Interactivity.Behavior behavior = new ESRI.ArcGIS.Client.Behaviors.ConstrainExtentBehavior()
            {
            ConstrainedExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-120,30,-60,60)
            };
System.Windows.Interactivity.Interaction.GetBehaviors(Map).Add(behavior);
0 Kudos
PatrickBrooke
New Contributor II
Thanks hc,

I was working towards a workaounds just like that. Works perfectly, thanks for posting that.
0 Kudos
KandaceKochivar
New Contributor II
hi patrickbrooke
I had the same problem as yours and i implemented  it with code (insert this snippet in loaded event) and it works (I don't know why???)

System.Windows.Interactivity.Behavior behavior = new ESRI.ArcGIS.Client.Behaviors.ConstrainExtentBehavior()
            {
            ConstrainedExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-120,30,-60,60)
            };
System.Windows.Interactivity.Interaction.GetBehaviors(Map).Add(behavior);


Hi!  I'm just starting out with Silverlight (and chose to learn on SL 4...) and encountered this same error.  Could you please explicitly tell me where to place this coded workaround?  i.e. Does it go in the vb/c# code behind page for MainPage.xaml or in MainPage.xaml or elsewhere?  Where should I put it in the code structure?

Thanks in advance!
0 Kudos
hcgis
by
New Contributor III
in your MainPage.xaml you insert the  usercontol loaded event like this


<UserControl x:Class="yourprojectname.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
.............
   Loaded="UserControl_Loaded"
..............


>

and in the codebehind MainPage.xaml.cs you put :   

private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
         System.Windows.Interactivity.Behavior behavior = new ESRI.ArcGIS.Client.Behaviors.ConstrainExtentBehavior()
             {
                  ConstrainedExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-120,30,-60,60)
             };
          System.Windows.Interactivity.Interaction.GetBehaviors(Map).Add(behavior);


        }
i hope that helps you
0 Kudos
hcgis
by
New Contributor III
hi patrickbrooke
Did you find any workaround for the slow loading for the featurelayer discussed in this thread http://forums.esri.com/Thread.asp?c=158&f=2455&t=302251&mc=12#952400

thanks
0 Kudos
KevinSesock
New Contributor
Greetings all, sorry to dredge up an old thread. New to ArcGIS, Silverlight, et al, and having a bit of trouble.

When attempting to implement the above code, I'm getting a "type or namespace name 'Behavior' does not exist in the namespace 'ESRI.ArcGIS.Client' (are you missing an assembly reference?)" Since I'm new to the API, I'm finding that most information and documentation applies to the 1.x version and not to 2.0, but I can't find anywhere to reference the Behavior namespace. Are you guys utilizing the old version of the API, or should this be pulling from http://schemas.esri.com/arcgis/client/2009?

Thanks for the help, and my apologies for the stupid question.
0 Kudos
JenniferNery
Esri Regular Contributor
It might be easier to use Expression Blend for this or you can also do this:

Add reference to the following assemblies:
ESRI.ArcGIS.Client.Behaviors.dll
System.Windows.Interactivity

Having the following XAML namespace definitions:
xmlns:esri="http://schemas.esri.com/arcgis/client/2009
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
should be sufficient.

This will allow you to
    <i:Interaction.Behaviors>
          <esri:ConstrainExtentBehavior ConstrainedExtent="-120,30,-60,60" />
    </i:Interaction.Behaviors>

Jennifer
0 Kudos
KevinSesock
New Contributor
Does anyone have a workaround for ShowCoordinatesBehavior? Or do we have any idea on a fix from ESRI on this in 2.1?
0 Kudos
JenniferNery
Esri Regular Contributor
Hi Kevin,

What issues are you having with ShowCoordinatesBehavior?
0 Kudos