Select to view content in your preferred language

Push Value from MapTip to VB

2569
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
this is what I would do... in my main class vb page I would create a public sub something like this  assuming your video files are WMV and showVideo is name of the MediaElement control in the xaml page

    Public Sub PlayVideo(videoName As String)
        Dim Address = New Uri(Application.Current.Host.Source, "../Video/" + videoName + ".wmv")
        Me.showVideo.Source = Address
    End Sub


I would then change my command class like this
Public Class MapTipValueCommand1
    Implements ICommand

    Private _mainPage As MainPage

    Public Sub New(mainPage As MainPage)
        Me._mainPage = mainPage
    End Sub


    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))
        Dim videoName = result2("NAME").ToString()
        Me._mainPage.PlayVideo(videoName)

    End Sub

End Class
0 Kudos
JayKappy
Frequent Contributor
That makes perfect sense....BUT....here goes again....lol...

Can you explain the addition of this....what is it for???
    Private _mainPage As MainPage

    Public Sub New(ByVal mainPage As MainPage)
        Me._mainPage = mainPage
    End Sub


Second...As soon As I do this I get blue squiggly lines un the red text below.....this is the text that i placed in main page vb code....
With this error:
Argument not specified for parameter 'mainPage' of 'Public Sub New(mainPage As MainPage)'.

#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
0 Kudos
IgressT
Emerging Contributor
sending the instance of main page to the command class in constructor
    Private _mainPage As MainPage

    Public Sub New(ByVal mainPage As MainPage)
        Me._mainPage = mainPage
    End Sub



and make this change (in red)
#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(Me)       
            End If
            Return Me.m_mapTipValueCommand1
        End Get

    End Property
#End Region
0 Kudos
JayKappy
Frequent Contributor
Should I set the Media Element up with a Variable for the source in XAML?
That way in the vb when I set the source it works....right now I can get the medial player to open but no video displays...

Current:
<MediaElement x:Name="mPlayer2" Width="300" Height="250" AutoPlay="False" Source="/Videos/halo.mp4" MediaOpened="Element_MediaOpened" />

Variable:
<MediaElement x:Name="mPlayer2" Width="300" Height="250" AutoPlay="False" Source="Variable Here" MediaOpened="Element_MediaOpened" />

Or get rid of the source setting in XAML all together???

In the code below I get the videoname returned and it works great...."/Videos/halo.mp4" gets returned, which is the correct value....so all the code is workign up to this point...
Now I just have to set the source of the media element...thats where my above question comes from....Shoudl I set the Source in XAML to a varaible and then changes the value of that variable in VB? I know that I cannot set the source in XAML because I dont know it untill I get it back from the class we created.....

For the example below I just tried to hard code it to the value....again the Media Element opens with showign the buttons etc....but no video
Dosent seem that the Media Elements Source is being set correctly...
I can see the light...were so close...just cant determine how to set the source correctly....
I have the file in my poject in a folder called Videos...there where I am getting /Videos/halo.mp4 from...uggggggggggg

   
Public Sub PlayVideo(ByVal videoName As String)
' return video path and name
        MessageBox.Show(videoName)
        
' Hard Code the Path adn File
        Dim Address = New Uri(Application.Current.Host.Source, "/Videos/halo.mp4")
' Set the source of the medie element        
        Me.mPlayer2.Source = Address
' Open the media player
        ShowMediaPlayerPanelNew.Begin()
' Start the media player
        mPlayer2.Play()
End Sub



Just reviewing this again and if I set a test Source in XAML and comment out the Source setting in VB it works fine, although hardcoded....if I uncomment them the video is not playing but I am getting the messagebox to return the files name and location...So what you have done so far is what I asked and I thank you very much....confused because I even tried to hard code the path and video name (of which is in the project)....

ONce again confusion....

Thank you very much for your help...very appreciated...if you have any further ideas about why the video wont load or syntax things you can see please pass them on....

THanks Again

It seems my problem now is that I canot set teh source from vb...The above code shoudl be working....or I have a minor syntax error...
0 Kudos
JayKappy
Frequent Contributor
I dont understand...I have this workign both ways.  With the 2 classes created and from within the vb script using a tag to push the value...

In both cases I can get the value for the path /Videos/halo.mp4
Videos is the folder in the project
halo.mp4 is the file in the project.

In both cases I can set the source in the XAML and it works fine....
Source="/Videos/halo.mp4"

BUT i cannot get, In either case, the video to work when I try and set the path from the variable being passed...NOT EVEN hard coded....

As soon as I try to set the Source in VB the medial player comes up with the buttons but no video being played....ugggggggggg


' Show media PLayer
ShowMediaPlayerPanelNew.Begin()
mPlayer2.Source = New Uri("../Videos/halo.mp4")
mPlayer2.Stop()
mPlayer2.Play()


' Show media PLayer
ShowMediaPlayerPanelNew.Begin()
mPlayer2.Source = New Uri(".." + videoName)
mPlayer2.Stop()
mPlayer2.Play()

' Show media PLayer
ShowMediaPlayerPanelNew.Begin()
Dim Address = New Uri(Application.Current.Host.Source, videoName)
mPlayer2.Stop()
mPlayer2.Play()

' Show media PLayer
ShowMediaPlayerPanelNew.Begin()
Dim Address = New Uri(Application.Current.Host.Source, ".." + videoName)
mPlayer2.Stop()
mPlayer2.Play()
0 Kudos
IgressT
Emerging Contributor
I am not sure where you are wrong but I made a quick check and its working for me (or may its not what you want) anyways... see the attached pic

all i did was in my XAML i put

        <MediaElement x:Name="showVideo"
                      Height="161"
                      Width="215"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Top"
                      IsMuted="True"
                      AutoPlay="True">
        </MediaElement>


In my main vb page i put a method

    Public Sub PlayVideo(videoName As String)
        Dim Address = New Uri(Application.Current.Host.Source, "../Video/" + videoName + ".wmv")
        Me.showVideo.Source = Address
    End Sub


and all other code is same as I put in my previous post
0 Kudos
JayKappy
Frequent Contributor
This is driving me NUTS...This is what I have...maybe you can take a glance and see one last time if you see anything...



<esri:FeatureLayer ID="MG_BusStops" Visible="False" 
      Url="http://gis.org/arcgis/rest/services/MG_Test/MapServer/8" 
      Renderer="{StaticResource BusStopUniqueRenderer}">
    <esri:FeatureLayer.OutFields>
          <!-- OUTPUT FIELDS THAT ARE TO BE RETURNED IN THE MAP TIPS-->
          <sys:String>ELEM_TEXT</sys:String>
           <sys:String>Route</sys:String>
          <sys:String>Location</sys:String>
           <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 ElementName=mainPage,Path= MapTipValueCommand1}"
                                                                CommandParameter="{Binding}" />                                         
                    </Grid>
                  </StackPanel> 
               </Grid>    
           </Border>
        </esri:FeatureLayer.MapTip>
</esri:FeatureLayer>

<!-- Down further in the xaml file...in the map -->

                <Grid x:Name="Media3PlayerGrid" Height="0" RenderTransformOrigin="0.5,0.5">
                    <Grid.RenderTransform>
                        <ScaleTransform x:Name="ResultsMedia3ScaleTransformNew" ScaleX="0" ScaleY="0" />
                    </Grid.RenderTransform>
                    <Canvas>
                        <MediaElement x:Name="mPlayer3" Width="300" Height="250" MediaOpened="Element_MediaOpened3" MediaEnded="Element_MediaEnded3" AutoPlay="True" />
                        <Button x:Name="bPlay3" Background="Green" Width="40" Height="20" Canvas.Left="8" Canvas.Top="220" Content="Play3" Click="bPlay_Click3" />
                        <Button x:Name="bPause3" Background="Yellow" Width="40" Height="20" Canvas.Left="112" Canvas.Top="220" Content="Pause3" Click="bPause_Click3" />
                        <Button x:Name="bStop3" Background="Red" Width="40" Height="20" Canvas.Left="216" Canvas.Top="220" Content="Stop3" Click="bStop_Click3" />
                        <Button x:Name="bHide3" Background="Red" Width="40" Height="20" Canvas.Left="260" Canvas.Top="220" Content="Hide3" Click="bHide_Click3" />
                        <TextBlock Foreground="Black" Margin="5"  Canvas.Left="10" Canvas.Top="260" VerticalAlignment="Center">Seek To</TextBlock>
                        <Slider Name="timelineSlider3" Margin="5" Width="180" Canvas.Left="60" Canvas.Top="260"  ValueChanged="SeekToMediaPosition3"/>
                    </Canvas>
                </Grid>




In the main Class of the MainPage.xaml.vb

    Public Sub PlayVideo(ByVal videoName As String)
        MessageBox.Show("in PlayVideo")
        MessageBox.Show(videoName)
        ' I get the correct values being passed in the messageboxes above
       
        ' I cannot set the darn media player defined in the xaml here....ugggggggggggg       
        'Dim Address = New Uri(Application.Current.Host.Source, "../Videos/halo.mp4") 
        Dim Address = New Uri(Application.Current.Host.Source, "../Videos/" + videoName + ".mp4")
        Me.mPlayer3.Source = Address

        'mPlayer3.Source = New Uri("../Videos/halo.mp4")
        'mPlayer3.Source = New Uri("/Videos/halo.mp4")
        'mPlayer3.Source = New Uri("Videos/halo.mp4")    
End Sub


' Snip

#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(Me)
            End If
            Return Me.m_mapTipValueCommand1
        End Get

    End Property
#End Region

End Class


Public Class MapTipValueCommand1
    Implements ICommand

    Private _mainPage As MainPage

    Public Sub New(ByVal mainPage As MainPage)
        Me._mainPage = mainPage
    End Sub

    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())
        Dim videoName = result2("Video").ToString()
        Me._mainPage.PlayVideo(videoName)

    End Sub
End Class
0 Kudos
IgressT
Emerging Contributor
Your codes good...  May be silverlight doesnot play .mp4 files... just a thought
0 Kudos
JayKappy
Frequent Contributor
I was thinking that but as I stated if I set the source on in the xaml file the video plays fine...I dont know what to do...maybe I will try and replace the mp4 file

The below works fine:
MediaElement x:Name="mPlayer2" Width="300" Height="250" AutoPlay="True" Source="/Videos/halo.mp4"/>

ugggggggggggggggggggggggggggggg

I do really appreciate yoru time and efforts to hlep me....while I am 99% there...the most important part is elluding me....I thank you for your patience....yoru help is very appreciated....

Guess I am going to have to keep staring at it...
0 Kudos
JayKappy
Frequent Contributor
you nkow what...I think you may be right.....

I have the mp4 file defined in the xaml and it works fine.
I remove the source setting in xaml and try and set it in vb and it does not work.

I removed the source setting in XAML
I replace the mp4 with a wmv and it is appearing to work....wow..

I have to go back and make sure there is not source setting that I cannot see etc and do some testing but this is a good start...

Just very confused how I can set teh source in xaml to mp4 file and it plays but I cant get the same file to play from vb side of things...interesting...

THANKS A MILLION...after testing will give everything I have....
0 Kudos