Select to view content in your preferred language

Open Link in Childwindow

907
3
12-01-2011 05:18 AM
JayKappy
Frequent Contributor
I am trying to open a link in a child window from "Map Tip", and have been sort of successful. 

I can do this and a new window opens to Yahoo.com
<HyperlinkButton Content="Yahoo" VerticalAlignment="Top" Foreground="White" NavigateUri="http://www.yahoo.com" TargetName="_blank" />


Taking this a bit further I have a field in my data that has a URL in it...I can do this and open it.
<HyperlinkButton Content="Web Camera" VerticalAlignment="Top" Foreground="White" NavigateUri="{Binding [URL]}" TargetName="_blank" />


BUT what I want to do I open this in a child window so I can control size etc. and embed other things...
I started with this
<HyperlinkButton Content="(View)" Click="OpenTrafficCamera" VerticalAlignment="Center"/>


    Private Sub OpenTrafficCamera(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim OpenTrafficCameraViewer As New TrafficCamera_Viewer() 
        OpenTrafficCameraViewer.Show()
    End Sub


In the Child Window I have a Webbrowser
<WebBrowser x:Name="webbrowserTrafficCameras" Height="450" Width="750" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,15,0,0"/>


OnLoaded I simple set the Navigate to this
webbrowserTrafficCameras.Navigate(New System.Uri("http://yahoo.com"))


I CAN SEE YAHOO FINE....

BUT MY ISSUE Is how do I pass the URL from the Attribute Value in the Dataset to the child window to set the Navigate...this way each location has its own URL to navigate too.

I cant see how to pass the URL attribute value for that specific record that the map tp is being applied to?

Thoughts?
0 Kudos
3 Replies
JayKappy
Frequent Contributor
I got this far...I was able to place a tag on the hyperling button and get the value to VB where I am now opening
my Childwindow...
Still need to pass the Variable to the child window?????  Then I can set the source of the webbrowser in
the childvindow.

How can I pass the varaible in VB to the Childwindow?

XAML
   <HyperlinkButton Content="(View)" Click="OpenTrafficCamera" Tag="{Binding [URL]}" VerticalAlignment="Center"/>

VB
    Private Sub OpenTrafficCamera(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        Try
            Dim varID As HyperlinkButton = DirectCast(sender, HyperlinkButton)
            If varID IsNot Nothing Then
                If varID.Tag IsNot Nothing Then
                    Dim ID As String = varID.Tag.ToString()

                    MessageBox.Show(ID)

                    Dim OpenTrafficCameraViewer As New TrafficCamera_Viewer() 
                    OpenTrafficCameraViewer.Show()

                End If
            End If
            'Handle exception
        Catch ex As Exception
        End Try

    End Sub
0 Kudos
JayKappy
Frequent Contributor
Think I got it....
0 Kudos
JayKappy
Frequent Contributor
Parent XAML:
 <HyperlinkButton Content="(View)" Click="OpenTrafficCamera" Tag="{Binding [URL]}" VerticalAlignment="Center"/>


Parent VB:
    Private Sub OpenTrafficCamera(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Try
            Dim varID As HyperlinkButton = DirectCast(sender, HyperlinkButton)
            If varID IsNot Nothing Then
                'MessageBox.Show(varID.Tag)
                If varID.Tag IsNot Nothing Then
                    Dim ID As String = varID.Tag.ToString()
                    Dim OpenTrafficCameraViewer As New TrafficCamera_Viewer()
                    OpenTrafficCameraViewer.URL1 = ID
                    OpenTrafficCameraViewer.Show()
                End If
            End If
            'Handle exception
        Catch ex As Exception
        End Try
    End Sub


Child Window XAML:
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Vertical">
            <TextBlock x:Name="txtName" Margin="0,10,0,30"/>
            <Border BorderBrush="Black" BorderThickness="4" Height="370" Width="460" >
                <WebBrowser x:Name="webbrowserTrafficCameras" Height="350" Width="450" ScrollViewer.VerticalScrollBarVisibility="Disabled"
                            HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0"/>
            </Border>
        </StackPanel>
    </Grid>


Child Window VB:
Imports System.Windows.Controls
Imports System.Windows

Partial Public Class TrafficCamera_Viewer
    Inherits ChildWindow

    'Private m_Value As Integer
    Public Property URL1() As String
        Get
            Return m_URL1
        End Get
        Set(ByVal value As String)
            m_URL1 = value
        End Set
    End Property
    Private m_URL1 As String

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub UserControl_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Me.txtName.Text = Me.URL1
        Dim Test As String = URL1
        webbrowserTrafficCameras.Navigate(New System.Uri(Test))
    End Sub

End Class
0 Kudos