Select to view content in your preferred language

Push Value from MapTip to VB

2962
30
06-14-2011 09:49 AM
JayKappy
Frequent Contributor
I have a MapTip that is returning a value from a field....I need this value to be pushed to the VB code so I can do soemthing with it...

Can that be done...Say inthe Map Tip below I have this....when I click the Button it sends a Binding Value from a field to the VB Sub....

This is the field that I need the bound field value "{Binding [Field1]}" sent to the vb Sub "doThis" as seen below...

From a MapTip can I send a Binding Value to a VB sub ????

THanks

<!-- Snip inside MapTip of Feature --> 

<StackPanel Orientation="Vertical">                                              
                                                            
 <Button x:Name="button" Background="Green" Width="40" Height="20" Content="button" Click="doThis"  SEND TO VB SUB="{Binding[Field1]}" />
                                              
</StackPanel>

<!-- Snip --> 
0 Kudos
30 Replies
IgressT
Emerging Contributor
I have a MapTip that is returning a value from a field....I need this value to be pushed to the VB code so I can do soemthing with it... 

Can that be done...Say inthe Map Tip below I have this....when I click the Button it sends a Binding Value from a field to the VB Sub.... 

This is the field that I need the bound field value "{Binding [Field1]}" sent to the vb Sub "doThis" as seen below... 

From a MapTip can I send a Binding Value to a VB sub ???? 

THanks 

<!-- Snip inside MapTip of Feature --> 

<StackPanel Orientation="Vertical">                                              
                                                            
 <Button x:Name="button" Background="Green" Width="40" Height="20" Content="button" Click="doThis"  SEND TO VB SUB="{Binding[Field1]}" />
                                              
</StackPanel>

<!-- Snip --> 


This works for me (code in C#)...

            <!-- Snip inside MapTip of Feature -->

            <StackPanel Orientation="Vertical">

                <Button x:Name="button"
                        Background="Green"
                        Width="40"
                        Height="20"
                        Content="button"
                        Command="{Binding GetMapTipValue}"
                        CommandParameter="{Binding ElementName=MyMapTip}"
            </StackPanel>

            <!-- Snip -->



and in the command


        private RelayCommand<object> _getMapTipValue;
        public RelayCommand<object> GetMapTipValue
        {
            get
            {
                if (this._getMapTipValue == null)
                {
                    this._getMapTipValue = new RelayCommand<object>(GetMapTipValueRelayMethod);
                }
                return this._getMapTipValue;
            }
        }
        private void GetMapTipValueRelayMethod(object commandParameter)
        {
            var result = (ESRI.ArcGIS.Client.Toolkit.MapTip)commandParameter;
            var result2 = (IDictionary<string, object>)result.ItemsSource;
            MessageBox.Show(result2["Field1"].ToString());
        }

0 Kudos
JayKappy
Frequent Contributor
Thanks for your responce...I converted to VB but am getting errors on teh RelayCommand not being defined in VB..In RED below...

Do you have that defined above in your CS page?


   Private _getMapTipValue As RelayCommand(Of Object)
    Public ReadOnly Property GetMapTipValue() As RelayCommand(Of Object)
        Get
            If Me._getMapTipValue Is Nothing Then
                Me._getMapTipValue = New RelayCommand(Of Object)(AddressOf GetMapTipValueRelayMethod)
            End If
            Return Me._getMapTipValue
        End Get
    End Property
    Private Sub GetMapTipValueRelayMethod(ByVal commandParameter As Object)
        Dim result = DirectCast(commandParameter, ESRI.ArcGIS.Client.Toolkit.MapTip)
        Dim result2 = DirectCast(result.ItemsSource, IDictionary(Of String, Object))
        MessageBox.Show(result2("Field1").ToString())
    End Sub
0 Kudos
IgressT
Emerging Contributor
I am using the MVVM lite framework I am not sure if you are using it but you can create a ICommand and do the same thing...
0 Kudos
JayKappy
Frequent Contributor
Sort of lost me on that one....I tried this..and getting error...seems the error is on the Object...as there is a blue squiggly line under each....

System.Windows.Input.ICommand has no type parameters and so cannot have type arguments

THanks for your time and patience....

    Private _getMapTipValue As ICommand(Of Object)
    Public ReadOnly Property GetMapTipValue() As ICommand(Of Object)
        Get
            If Me._getMapTipValue Is Nothing Then
                Me._getMapTipValue = New ICommand(Of Object)(AddressOf GetMapTipValueRelayMethod)
            End If
            Return Me._getMapTipValue
        End Get
    End Property
0 Kudos
IgressT
Emerging Contributor
Ok I will be clear...

In my XAML I have this

<!-- Snip inside MapTip of Feature -->

                    <Button Content="GetMapTipValue"
                            Height="30"
                            Width="150"
                            Command="{Binding MapTipValueCommand}"
                            CommandParameter="{Binding ElementName=MyMapTip}">
                         
                    </Button>

<!-- Snip inside MapTip of Feature -->


In my ViewModel class I have this
 
       private MapTipValueCommand mapTipValueCommand;
        public MapTipValueCommand MapTipValueCommand
        {
            get
            {
                if (this.mapTipValueCommand == null)
                {
                    this.mapTipValueCommand = new MapTipValueCommand();
                }
                return this.mapTipValueCommand;
            }
        }


my command class looks like this
    
public class MapTipValueCommand:ICommand
    {

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            var result = (ESRI.ArcGIS.Client.Toolkit.MapTip)parameter;
            var result2 = (IDictionary<string, object>)result.ItemsSource;
            MessageBox.Show(result2["XXX"].ToString());
            
        }
    }
0 Kudos
JayKappy
Frequent Contributor
I really appreciate your help with this....I am not a wiz by any means, as you can already see....
I have a project that already has a bunch of code in it xaml adn vb. I have a couple classes in the vb code so placing this code is challenging...

XAML:
<!--  Snip from Map Tip  -->
<Button x:Name="bTurnOn3"  Background="Red" Width="40" Height="20" Content="TurnON" Click="bTurnOn_Click3"
       Command="{Binding MapTipValueCommand}"
       CommandParameter="{Binding ElementName=MyMapTip}"/>
<!--  Snip from Map Tip  -->


VB: Right in the middle of my vb code that exists, where all the other code is I placed this

    Private m_mapTipValueCommand As MapTipValueCommand
    Public ReadOnly Property MapTipValueCommand() As MapTipValueCommand
        Get
            If Me.m_mapTipValueCommand Is Nothing Then
                Me.m_mapTipValueCommand = New MapTipValueCommand()
            End If
            Return Me.m_mapTipValueCommand
        End Get
    End Property



Then at the bottom I created the new class with this: Although I get an error on the Implements ICommand:
ERRORS:
Class 'MapTipValueCommand' must implement 'Sub Execute(parameter As Object)' for interface 'System.Windows.Input.ICommand'.
Class 'MapTipValueCommand' must implement 'Function CanExecute(parameter As Object) As Boolean' for interface 'System.Windows.Input.ICommand'.
Class 'MapTipValueCommand' must implement 'Event CanExecuteChanged(sender As Object, e As EventArgs)' for interface 'System.Windows.Input.ICommand'.

Public Class MapTipValueCommand
    Implements ICommand

    Public Function CanExecute(ByVal parameter As Object) As Boolean
        Return True
    End Function

    Public Event CanExecuteChanged As EventHandler

    Public Sub Execute(ByVal parameter As Object)
        Dim result = DirectCast(parameter, ESRI.ArcGIS.Client.Toolkit.MapTip)
        Dim result2 = DirectCast(result.ItemsSource, IDictionary(Of String, Object))
        MessageBox.Show(result2("Field1").ToString())

    End Sub
End Class
0 Kudos
IgressT
Emerging Contributor
Try something like this...

Public Class MapTipValueCommand
    Implements ICommand

    Public Function CanExecute(parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
        Return True
    End Function

    Public Event CanExecuteChanged(sender As Object, e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged

    Public Sub Execute(parameter As Object) Implements System.Windows.Input.ICommand.Execute
        Dim result = DirectCast(parameter, ESRI.ArcGIS.Client.Toolkit.MapTip)
        Dim result2 = DirectCast(result.ItemsSource, IDictionary(Of String, Object))
        MessageBox.Show(result2("Field1").ToString())
    End Sub
End Class
0 Kudos
JayKappy
Frequent Contributor
No errors there so we are getting close....although the message box does not appear when I click the button in the Map Tip....

This is what I have so far...for some reason the message box wont open...

I additionally added a message box in the ReadOnly Porperty that was placed inthe main vb code area....the message box is not being fired off....

No Message Box pops up giving me the value of Field1...

I THANK YOU VERY Much for your help...it is very appreciated...

Thoughts? Something that I can focus on? does the command parameter element name have to reflect something else?



XAML:
<esri:FeatureLayer ID="Stops" Visible="False"        
Url="http://gi.org/arcgis/rest/services/MG_Test/MapServer/8" 
       Renderer="{StaticResource BusStopUniqueRenderer}">
   <esri:FeatureLayer.OutFields>
        <sys:String>Video</sys:String>
   </esri:FeatureLayer.OutFields>
   <esri:FeatureLayer.MapTip >
       <Border esri:GraphicsLayer.MapTipHideDelay="00:00:01.5" CornerRadius="10" 
              BorderBrush="#FF222957" BorderThickness="0" Margin="0,0,15,15">
       <Border.Background>
       <LinearGradientBrush EndPoint="1.038,1.136" StartPoint="0.015,0.188">
           <GradientStop Color="#FFD1DFF2"/>
           <GradientStop Color="#FF092959" Offset="0.946"/>
       </LinearGradientBrush>
       </Border.Background>
       <Border.Effect>
           <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
       </Border.Effect>  
       <Grid>
           <StackPanel Orientation="Vertical" Margin="10,10,0,10" VerticalAlignment="Center">
              <Grid>                                            
                  <Button Content="GetMapTipValue" 
                      Width="100" Height="20"
                      Command="{Binding MapTipValueCommand}"
                      CommandParameter="{Binding ElementName=MyMapTip}"/>              
              </Grid>
           </StackPanel> 
       </Grid>    
       </Border>
   </esri:FeatureLayer.MapTip>
</esri:FeatureLayer>



VB Code that sits where all the main vb code currently exists
    
Private m_mapTipValueCommand As MapTipValueCommand    
Public ReadOnly Property MapTipValueCommand() As MapTipValueCommand

        Get
            If Me.m_mapTipValueCommand Is Nothing Then
                Me.m_mapTipValueCommand = New MapTipValueCommand()
            End If
            Return Me.m_mapTipValueCommand
            MessageBox.Show("In the Get")        
        End Get

    End Property


VB Code placed outside the main code creating a new class.
Public Class MapTipValueCommand
    Implements ICommand

    Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
        Return True
    End Function

    Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged

    Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
        Dim result = DirectCast(parameter, ESRI.ArcGIS.Client.Toolkit.MapTip)
        Dim result2 = DirectCast(result.ItemsSource, IDictionary(Of String, Object))
        MessageBox.Show(result2("Video").ToString())
    End Sub
End Class
0 Kudos
IgressT
Emerging Contributor
See the attached project (its in C#, build the solution to run it)
0 Kudos