Select to view content in your preferred language

MaintainExtentBehavior problem

1513
10
01-07-2011 10:36 AM
ThaoNguyen
Emerging Contributor
I tried to use MaintainExtentBehavior but got the following error:

A value of type 'MaintainExtentBehavior' cannot be added to a collection or dictionary of type 'BehaviorCollection'.

My code:
  <i:Interaction.Behaviors>        
          <esriBehaviors:MaintainExtentBehavior x:Uid="meb" />
  </i:Interaction.Behaviors>

My namespaces:
xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors" 
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 


Any clues why I got that error??

Thanks!
0 Kudos
10 Replies
JenniferNery
Esri Regular Contributor
Kindly look at the SDK sample for MaintainExtentBehavior http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MaintainExtentBehavior

The error message in your other post seem related to this. In both cases you were using "x:Uid".  Have you tried compiling your app without this?
0 Kudos
ThaoNguyen
Emerging Contributor
Kindly look at the SDK sample for MaintainExtentBehavior http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MaintainExtentBehavior

The error message in your other post seem related to this. In both cases you were using "x:Uid".  Have you tried compiling your app without this?


Our application requires x:uid; otherwise, it won't compile.
To me, x:uid should not affect this, if it does, it doesn't make sense.
0 Kudos
JenniferNery
Esri Regular Contributor
Maybe the error is unrelated to "x:Uid" then. Have you tried the recreating SDK sample? Was the issue related to xaml namespace definition or referencing the correct assemblies?

I think you just need to update this line.
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"


The type mismatch may be caused by this.

Here's more information about the error you got: http://msdn.microsoft.com/en-us/library/bb546975(v=VS.100).aspx
0 Kudos
ThaoNguyen
Emerging Contributor
Maybe the error is unrelated to "x:Uid" then. Have you tried the recreating SDK sample? Was the issue related to xaml namespace definition or referencing the correct assemblies?

I think you just need to update this line.
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"


The type mismatch may be caused by this.

Here's more information about the error you got: http://msdn.microsoft.com/en-us/library/bb546975(v=VS.100).aspx


I didn't try the sample itself, I just learn how it is done and do it in my own application.
changing the xmlns as you suggested didn't resolve the problem either :(.
0 Kudos
JenniferNery
Esri Regular Contributor
I don't see why you would get this error message. I found this related thread: http://forums.arcgis.com/threads/3323-SL4-Breaks-ESRI-Behaviors Can you try adding the behavior in code-behind? Both methods should work actually (XAML / code-behind).
0 Kudos
ThaoNguyen
Emerging Contributor
I don't see why you would get this error message. I found this related thread: http://forums.arcgis.com/threads/3323-SL4-Breaks-ESRI-Behaviors Can you try adding the behavior in code-behind? Both methods should work actually (XAML / code-behind).


Just come back to this issue.  I think the sample xaml code posted is not correct.  The MaintainExtentBehavior class does not exist in Arcgis client dll.  It is in ESRI.ArcGIS.Client.Behaviors.dll.
I haven't got this worked yet.
When I follow the sample, I got an error:
The tag 'Interaction.Behaviors' does not exist in XML namespace 'http://schemas.microsoft.com/expression/2010/interactivity'.

I also tried the code behind but I got a compilation error because the version of the System.interactivity.dll did not match (as below).  I installed expression4 and hoping it would provide me System.interactivity.dll version 4, but it was version 3.5.  I'm not sure what to do now.  Can't find where I can get version 4, can't try the sample xaml code either.

Assembly 'ESRI.ArcGIS.Client.Behaviors, Version=2.1.0.446, Culture=neutral, PublicKeyToken=29c6dd6e8553d944' uses 'System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Windows.Interactivity, Version=3.5.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35'
0 Kudos
JenniferNery
Esri Regular Contributor
I think the SDK sample is correct.

Are you using VS 2010 with SL API v2.1? If so, the following is supported
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009" 


Any public XAML-able properties that belong to esri namespace, except for the Primitives can be accessed through namespace as long as you have reference to their assemblies.

This means you still need to add reference to ESRI.ArcGIS.Client.Behavior.dll in your project in order to do the following:
<esri:MaintainExtentBehavior .../>


Now that you mentioned the error message, I think the issue is resolving this namespace and adding reference to the correct version in your project.
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"


An older may have been installed and it picks up the older version, you can try to add hint path as described here http://forums.silverlight.net/forums/p/194833/453085.aspx
0 Kudos
ThaoNguyen
Emerging Contributor
I think the SDK sample is correct.

Are you using VS 2010 with SL API v2.1? If so, the following is supported
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009" 


Any public XAML-able properties that belong to esri namespace, except for the Primitives can be accessed through namespace as long as you have reference to their assemblies.

This means you still need to add reference to ESRI.ArcGIS.Client.Behavior.dll in your project in order to do the following:
<esri:MaintainExtentBehavior .../>


Now that you mentioned the error message, I think the issue is resolving this namespace and adding reference to the correct version in your project.
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"


An older may have been installed and it picks up the older version, you can try to add hint path as described here http://forums.silverlight.net/forums/p/194833/453085.aspx


I'm using VS 2010 with WPF API v2.1.  I already tried what you suggested above except the hint path, nothing worked :(.  Will try to add hint path when I have a chance.
0 Kudos
ThaoNguyen
Emerging Contributor
I've never got MaintainExtentBehavior worked for my WPF application.  I wonder if this function only works for Silverlight?  Am I right?
I no longer get compiled errors as mentioned in this original post, but got an error at runtime as below:
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

This was because I added
<i:Interaction.Behaviors>        
        <esriBehaviors:MaintainExtentBehavior x:Uid="meb" />
</i:Interaction.Behaviors>

I removed the xaml code and tried to add the code below to the behind code as suggested, I didn't get runtime error but the map extent just didn't change when I resized my window.  It didn't work.

System.Windows.Interactivity.Behavior behavior = new ESRI.ArcGIS.Client.Behaviors.MaintainExtentBehavior();
System.Windows.Interactivity.Interaction.GetBehaviors(MyMap).Add(behavior);
0 Kudos