Constrain Extent Behavior Questions.

571
5
05-18-2011 05:00 AM
VincenzoPiscitelli
New Contributor
Silverlight API 2.2/.NET 4


  1. Is it possible to data bind to the ConstrainedExtent property of the behavior (MVVM)?

  2. How do you disable the behavior, that is defined in XAML, temporarily to allow for an extent change?

Let me elaborate on the 2nd point a little.

We have an application which contains a list of predefined boundaries, that when selected zooms to that boundary.  Once there, the user is constrained to that boundary unless they choose another boundary in the list.  In which case the behavior would need to be disabled, then re-enabled once the new extent has been zoomed to.

I have this all implemented the way I think it should be, but I get very inconsistent results.  See below.

  • Constraint is applied, but you can't zoom in.

  • Constraint is applied, but you get no "bounce" behavior when you try to pan outside of the extent.

  • Complete UI lock-up.

Just to restate, I am using MVVM.

Any information would be greatly appreciated.

Thanks in advance.
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
ConstrainedExtent is a DependencyProperty and will accept binding.

I'm not sure how you can temporarily disable this but you can maybe set ConstrainExtent to your base layer's FullExtent until you've established that the new extent is one of the regions that you want to set as your constrain?
0 Kudos
VincenzoPiscitelli
New Contributor
This is exactly what I'm doing.

Geography Changed Handler.
Messenger.Default.Register<PropertyChangedMessage<NavigableGeography>>(
                this,
                action =>
                {
                    if (action.NewValue.Extent != null)
                    {
                        if(MaxExtent == null)
                            MaxExtent = MapLayers["Base Map"].FullExtent;

                        ConstrainedExtent = MaxExtent;
                        Extent = action.NewValue.Extent.Expand(1.25);
                        ConstrainedExtent = Extent;
                    }
                });

XAML
        <!-- Map -->
        <esri:Map x:Name="map" 
            ext:AttachedProperties.BindableExtent="{Binding MapVM.Extent}" 
            Background="White" SnapToLevels="True" d:IsHidden="True" 
            IsLogoVisible="False" Layers="{Binding MapVM.MapLayers}" >
            <i:Interaction.Behaviors>
             <esri:ConstrainExtentBehavior ConstrainedExtent="{Binding MapVM.ConstrainedExtent, Mode=OneWay}" />
            </i:Interaction.Behaviors>
        </esri:Map>

This code snippet is in a ViewModel I created for the map.  MaxExtent, Extent and ConstrainedExtent are all properties of the ViewModel that raise PropertyChanged events.

When the application first loads, everything is fine.  I can pan and zoom.  The ConstrainedExtent is null because the "Base Map" hasn't loaded yet.

When the user chooses a geography to zoom to, the MaxExtent is populated and the ConstrainedExtent is set to that.

I then do the zoom by changeing the Extent property of the ViewModel and set the new ConstrainedExtent to the current Extent.

I have verified that all the values are set correctly in the ViewModel.

The only thing I am wondering about is what happens when the extent is not the same width:height ratio as the screen?  Could something be going on with that?

As stated above, the expected behavior would be that panning to the edges would produce the "bounce" effect and that I could zoom in, but not out farther than the ConstrainedExtent.

I do not get the bounce effect nor can I zoom in or out.  I am just locked to that extent.

If I then select to zoom to a different geography, it allows me, but I get the same behavior at the new extent.  Can't pan or zoom.
0 Kudos
BrentStevener
New Contributor II
This error happens when you don't have a reference to ESRI.ArcGIS.Client.Behaviors in your project. Add the reference and you should be able to add it without the error. [I had the same problem and fixed it earlier]
0 Kudos
VincenzoPiscitelli
New Contributor
This problem still exists for me.  I cannot get my map to behave in a way that mimics the sample.
0 Kudos
VincenzoPiscitelli
New Contributor
Any help would be appreciated.
0 Kudos