Select to view content in your preferred language

Binding to Envelope parameters on ZoomToAction

1375
3
07-29-2010 11:41 AM
MikeTischler
Emerging Contributor
Hi,
I'm creating a series of bookmarks with the names and extents of the bookmarks being bound to an external XML file.  I've added the XML as a date source in Expression Blend.  I've got a listbox like below:
<ListBox x:Name="Bookmarklistbox" ItemTemplate="{StaticResource bookmarkTemplate}" ItemsSource="{Binding categoryCollection}" >
</ListBox>


I've put the ItemTemplate in the UserControl resources and it looks like this:

<DataTemplate x:Key="bookmarkTemplate">
<StackPanel>
<TextBlock Text="{Binding name}"/>
<Button Name="bookmarkbutton" />
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<esriBehaviors:ZoomToAction TargetName="Map">
<esriBehaviors:ZoomToAction.Geometry>
<esriGeometry:Envelope
XMin="{Binding XMin}" YMin="{Binding YMin}" XMax="{Binding XMax}" YMax="{Binding YMax}"/>
</esriBehaviors:ZoomToAction.Geometry>
</esriBehaviors:ZoomToAction>
</i:EventTrigger>
</i:Interaction.Triggers>


Now, The button content shows up as it should with the correct bookmark name.  However, I can't get the Envelope parameters to bind without an error.  The error I'm receiving is "Object of System.Windows.Data.Binding cannot be converted to System.Double"

If I switch the button content to {Binding XMin}, the content changes to a coordinate...so I know I'm in the right neighborhood.  But, I can't seem to figure out how to bind this correctly.

Any thoughts?
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
Unfortunately these Envelope properties (XMin, YMin, XMax, YMax) are not dependency properties that's why you cannot bind to them.

Jennifer
0 Kudos
MikeTischler
Emerging Contributor
Ah - I see.  Thanks for filling me in.

I found a workaround (if anyone is interested).  First I changed my XML.  Where there were 4 properties(Xmin, Ymin,Xmax,Ymax) for each entry before, there is a single comma-delimited string now.  I can bind that to the button.tag in the data template and parse that string in code behind on the button's click event handler.  Then I create a new envelope, and pass the parsed string parts to the bounding box coordinates of the new envelope.  Finally, I call Map.ZoomTo(mynewenv) and it works.

Thanks,
mike
0 Kudos
MichaelLibio
Emerging Contributor
Unfortunately these Envelope properties (XMin, YMin, XMax, YMax) are not dependency properties that's why you cannot bind to them.

Jennifer


Is there a way to extend the Envelope class to include properties (like a wrapper) that are dependency properties?


public static readonly DependencyProperty BindableXMaxProperty = 
    DependencyProperty.Register(
    "BindableXMax", typeof(Double),


...

    );
public double BindableXMax
{
    get
    {
        return (Double)GetValue(BindableXMax);
    }
    set
    {
        this.XMax = value;
        SetValue(BindableXMaxProperty, value);
    }
}


Let me know what you think.

--Michael
0 Kudos