Select to view content in your preferred language

MaintainExtentBehavior problem

1551
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
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);


I tried a simple map application, it worked fine!  Don't know what may cause the problem I have.
0 Kudos