Select to view content in your preferred language

Push Value from MapTip to VB

2973
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
JayKappy
Frequent Contributor
Once again I thank you for your help and patience...
I grabbed you example and did a build in Visual Studio....no errors....I then ran it from VS

Now I get an error in the App.xaml.cs page on the ititializeComponent I get an XamlParseException occured error
Failed to create a System.Type from the text esri:legend

just tryign to get this to work adn then be able to disect it....having multuiple cs pages through out the project is confusing to me...where all my vb code is in the mainpage.xaml.vb...

But first yoru example....I guess there is an error on the esri:Legend?

Is the "MyMapTip" seen below in the COmmand Parameter pointing to something or is this jsut a general statement to the current MapTip
CommandParameter="{Binding ElementName=MyMapTip}">

THanks a million
0 Kudos
IgressT
Emerging Contributor
Once again I thank you for your help and patience...
I grabbed you example and did a build in Visual Studio....no errors....I then ran it from VS

Now I get an error in the App.xaml.cs page on the ititializeComponent I get an XamlParseException occured error
Failed to create a System.Type from the text esri:legend
Try deleting the legend style from App.xaml

just tryign to get this to work adn then be able to disect it....having multuiple cs pages through out the project is confusing to me...where all my vb code is in the mainpage.xaml.vb...

But first yoru example....I guess there is an error on the esri:Legend?

Is the "MyMapTip" seen below in the COmmand Parameter pointing to something or is this jsut a general statement to the current MapTip
CommandParameter="{Binding ElementName=MyMapTip}">
In the attachment I sent if you look carefully my CommandParameter is just CommandParameter="{Binding}" not CommandParameter="{Binding ElementName=MyMapTip}"
0 Kudos
JayKappy
Frequent Contributor
AGAIN thank you for your time and patience...I am learnign a ton here....especially if I can get this going...I have never had teh classes sepertated in folders and new class files...very excited to get thsi to work for that alone....

Alright I got yours to work....thats what I need....

I am tryign to create it like you have with the two folders and classes...I am very excited because this will be the first time I was able to do this...
I tried to recreate what you have...I create two folders and named them the same as above...I then created to new Classes in Each and brought in the code...

Here is what I have...I THINK I AM VERY CLOSE...I attached a word doc showing each of the tabs and where two of the errors are showing....

I just cant seem to get the folders and extra classes to all see each other...

Xaml:
Error:
The type 'ViewModel:MainPageViewModel' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

<!--  Snip User Control -->
     xmlns:ViewModel="clr-namespace:gislis2010_live.ViewModel">
<!--  Snip MapTip -->

    <UserControl.Resources>
        <ViewModel:MainPageViewModel x:Key="vm" />
    </UserControl.Resources>

<!--  Snip MapTip -->
    <Button Content="GetMapTipValue"
          Width="100"   Height="20"
          Command="{Binding Source={StaticResource vm},Path= MapTipValueCommand}"
          CommandParameter="{Binding}" />
<!--  Snip MapTip -->


In the folder Commands and in the MapTipValueCommand.vb class

Imports System
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Ink
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports System.Collections.Generic

Namespace gislis2010_live.Commands
    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 result2 = DirectCast(parameter, IDictionary(Of String, Object))
            MessageBox.Show(result2("Video").ToString())
        End Sub
    End Class
End Namespace


In the folder ViewModel and in the MainPageViewModel.vb class

I get green squiggly lines on the red line below....I think this is where my error is adn why it wont run because it wont see the "MapTipValueCommands" file and as such the "MapTipValueCommand" class

ERROR from Green Squiggly lines:
Name or type speficed in the imports gislis2010_live.Commands doesnt contain any public member or canoot be found. Make sure teh namespace or the type is defined and contains at lweast one public member. Make sure the imported element bnames dosent use any aliases.

Any thoughts why its telling me it cannot find it?
Imports System
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Ink
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports gislis2010_live.Commands

Namespace gislis2010_live.ViewModel
    Public Class MainPageViewModel
        Inherits DependencyObject
        Public Sub New()
        End Sub

#Region "Intersect command"
        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
#End Region

    End Class
End Namespace
0 Kudos
IgressT
Emerging Contributor
This works for me (VB version of my previous attachment ) build and run it
0 Kudos
JayKappy
Frequent Contributor
Man I owe you a bunch of cold ones.....I finally got it...with your help obviously

I was very confused on getting the connection going between the MainPage.xaml and the new class files I created.  (in reflection of your example of course)....

In the mainpage.xaml I was trying this:
xmlns:ViewModel="clr-namespace:gislis2010_live.ViewModel"
But was supposed to be
xmlns:ViewModel="clr-namespace:gislis2010_live.gislis2010_live.ViewModel"

Why is "gislis2010_live" repeated twice??????

By chaging this all the files were happy with each other and started talking....
I cannot thank you enough....

If anyone has any questions or wants any code exampels please feel free to contact me and I will give you anything I have....
Thanks a million....Very appreciated.
0 Kudos
JayKappy
Frequent Contributor
One more loaded thought.....Say I want to remove the class files that were created in the folders (MapTipViewModel, and MainPageViewModel)...could one place both classes in the MainPage.xaml.vb, instead of the two newly created vb files?

The reason I ask is that from that class where I return the value I am trying to run a story board that is defined on the MainPage.xaml with this... ShowMediaPlayerPanelNew.Begin() But it wont run because its in the new class.....and disconnected

        Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
            Dim result2 = DirectCast(parameter, IDictionary(Of String, Object))
            MessageBox.Show(result2("Video").ToString())
            ShowMediaPlayerPanelNew.Begin()  
        End Sub


It says that ShowMediaPlayerPanelNew.Begin is not declared...


1. I would like to be able to run the 2 classes from inside the MainPage.xaml.vb
Can this be done?
I tried this by coping the 2 classes into the MainPage.xaml.vb page outside the main class
Then removed the call to the ViewModel inteh UserControl in the mainpage.xaml
Then removed <ViewModel:MainPageViewModel x:Key="vm" /> from the UserControl.Resources from teh mainpage.xaml
Then changed the Button to reflect the class that is in the MainPage.xaml.vb
I CHANGED THE BINDING below because I was not referencing the new class file... That right?
         <Button Content="GetMapTipValue"
               Width="100"   Height="20"
               Command="{Binding MapTipValueCommand}"
               CommandParameter="{Binding}" />


2. How can I fire off the Story Board from within the New Class ... do I need to specify the MainPAge.xaml to run this? Or do I need a link back to the MainPage.xaml in the code (inherit)
I still need to reference media elements from the mainpage.xaml, and other grids etc.....to turn them on and off....In this case I am getting the value from teh video field and using that to turn on the media player and specify which video to play...

My Last 2 Questions I Promise....


THANKS A MILLION
0 Kudos
IgressT
Emerging Contributor
1. I would like to be able to run the 2 classes from inside the MainPage.xaml.vb
Can this be done?
Yes...I don't know if its right way to do or may be it is... anyways look at my code below
I tried this by coping the 2 classes into the MainPage.xaml.vb page outside the main class
Then removed the call to the ViewModel inteh UserControl in the mainpage.xaml
Then removed <ViewModel:MainPageViewModel x:Key="vm" /> from the UserControl.Resources from teh mainpage.xaml
Then changed the Button to reflect the class that is in the MainPage.xaml.vb
I CHANGED THE BINDING below because I was not referencing the new class file... That right?
Code:
<Button Content="GetMapTipValue"
Width="100" Height="20"
Command="{Binding MapTipValueCommand}"
CommandParameter="{Binding}" />
2. How can I fire off the Story Board from within the New Class ... do I need to specify the MainPAge.xaml to run this? Or do I need a link back to the MainPage.xaml in the code (inherit)
I don't know

MainPage.xaml.vb
Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
    End Sub

#Region "Intersect command"
    Private m_mapTipValueCommand1 As MapTipValueCommand1
    Public ReadOnly Property MapTipValueCommand1() As MapTipValueCommand1

        Get
            If Me.m_mapTipValueCommand1 Is Nothing Then
                Me.m_mapTipValueCommand1 = New MapTipValueCommand1()
            End If
            Return Me.m_mapTipValueCommand1
        End Get

    End Property
#End Region

End Class

Public Class MapTipValueCommand1
    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 result2 = DirectCast(parameter, IDictionary(Of String, Object))
        MessageBox.Show(result2("NAME").ToString())
    End Sub

End Class


MainPage.xaml
<UserControl x:Class="SilverlightApplication1_VB.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="400"
             x:Name="mainPage">    
    <Grid x:Name="LayoutRoot">
        <!-- Map Control -->
        <esri:Map x:Name="MyMap"
                  Extent="-15000000,2000000,-7000000,8000000">
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                                             Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
            <esri:FeatureLayer ID="MyFeatureLayer"
                               Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3">
                <esri:FeatureLayer.MapTip>
                    <Border esri:GraphicsLayer.MapTipHideDelay="00:00:05"
                            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 ElementName=mainPage,Path= MapTipValueCommand1}"
                                            CommandParameter="{Binding}" />
                                </Grid>
                            </StackPanel>
                        </Grid>
                    </Border>
                </esri:FeatureLayer.MapTip>
            </esri:FeatureLayer>
        </esri:Map>
    </Grid>
</UserControl>
0 Kudos
JayKappy
Frequent Contributor
Man I am so close....I have it sort fo working both ways...but theres always a BUT.....
uggggggg

This is what I am trying to do.....as the user hovers over a feature the map tip pops up. In the map tip there is a button....when clicked this buttons returns the value of the video field...this value is a media file that I want to play when the button is clicked....I went this route because its was the only way to determine which media file needs to be played....specific to the feature producing teh map tip

Doing this the second way I thought would elimintate the error I was getting, but its not.....

From the MapTipValueCommand1 I was getting the correct field value ("media file to play")
From within this new class I was trying to start the media player and pass this variable to it so it will know which fiel to play....
For testing purposes I was simply trying to run a storyboard to open the media player I created...but it seems that I am in the class and the Story board line not declared...I assume this is because its inside the created class????

'ShowMediaPlayerPanelNew' is not declared. It may be inaccessible due to its protection level.

    
Public Class MapTipValueCommand1
    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 result2 = DirectCast(parameter, IDictionary(Of String, Object))
        MessageBox.Show(result2("Video").ToString())
        ShowMediaPlayerPanelNew.Begin()    
  End Sub
End Class



I was hoping that once i had the value from the new class I could open the medial player and pass the value to the media player to play the correct file....

Does any of that make sense....There has to be a way to do this....at least run the storyboard to open the media player.....uggggg

THanks a million.....I am almost there.....


Can I do soemthing like this? Can I pass the value back to a sub in the main class of the vb page....then I can start the story board and specify the media file to play?

    Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
        Dim result2 = DirectCast(parameter, IDictionary(Of String, Object))
        MessageBox.Show(result2("Video").ToString())
        Call Sub in Main vb and pass the Video value to it and return Message box there    
  End Sub
0 Kudos
IgressT
Emerging Contributor
Can you share your solution 🙂
0 Kudos
JayKappy
Frequent Contributor
Well right now I dont really have a solution...I mean I can get the value to the class that was created but then I cant do anythign with it besides sending to a message box.  I am so burried in the new class that I cant run the Story Boards in the main xaml, I cant start a media player that was created in the main xaml....

Was going to be my question to you....now that you got the value being displayed in the new class what are you doing with it?

Will post what I have in a few minutes....
0 Kudos