locked
Using a MouseLeftButtonDown to navigate to another page

    Question

  • Hi,

    I'm slightly new to ASP.net and silverlight and any help would be great.

    I have a media element thats displays pictures (Taken from YetAnotherCarousel demo) and i have renamed it as '"me1" (without quotes)

    i have created an eventhandler called me1_MouseLeftButtonDown and using this handler I want to move to another page, for example default1.aspx

    To summarise I actually want to be able to click on "me1" and move to another page within the event handler. Is this possible? If so what is the correct code to navigate to the default1.aspx page? 

    Thanks for the help.

    Jas

    Monday, January 5, 2009 1:05 PM

Answers

  •  

    HtmlPage.Window.Navigate(new Uri("my.domain.com/default1.aspx", UriKind.Absolute));
     
    Monday, January 5, 2009 1:10 PM
  • Yes, the example I provided was specifically for something like Page.xaml

    Inside the Xaml file, you'll use the markup I provide. Just to be completely correct, here's the exact xaml for a hyperlink button in Silverlight that will link to default.aspx and contains a video named MyVideo.wmv

     <HyperlinkButton NavigateUri="http://foo.com/default.aspx">

             <MediaElement Source="http://foo.com/MyVideo.wmv" Stretch="Uniform" />

     </HyperlinkButton>

    There are some great tutorials here in the getting started section. Those will help explain the concept of a content control (which HyperlinkButton is), so the syntax will make more sense. For now, just understand that the hyperlinkbutton can contain just about anything you can mark up in xaml: images, video, other buttons, etc.

    The model is quite different from asp.net, but almost identical to that of WPF.

    Pete

    Tuesday, January 6, 2009 7:43 PM

All replies

  •  

    HtmlPage.Window.Navigate(new Uri("my.domain.com/default1.aspx", UriKind.Absolute));
     
    Monday, January 5, 2009 1:10 PM
  • Hi Jas

    Unless you have really good reason to do so, I wouldn't navigate on MouseLeftButtonDown.

    Since you're using a mediaelement, I assume you're just playing a video that shows the pictures. If that's the case, put the media element inside a HyperlinkButton control

    (air code)

    <HyperlinkButton x:Name="MyButton" NavigateUri="http://foo.com/default.aspx" Target="_blank">

       <MediaElement x:Name="me1" Source="..." />

    </HyperlinkButton>

    Monday, January 5, 2009 1:32 PM
  • Hi,

    Thanks for the help.

    Is it possible to do what you've (Psychlist1972 ) done above within the page.xaml.cs code. Within ASP.net you can set an image background to a hyperlink, but i can't seem to get it working with the xaml.cs.

    There is a Background control,but is that the correct control? If it is how do i set it as a picture or video.

    Thanks again for the help, really appreciate it.

    Jas

    Tuesday, January 6, 2009 3:43 PM
  • Yes, the example I provided was specifically for something like Page.xaml

    Inside the Xaml file, you'll use the markup I provide. Just to be completely correct, here's the exact xaml for a hyperlink button in Silverlight that will link to default.aspx and contains a video named MyVideo.wmv

     <HyperlinkButton NavigateUri="http://foo.com/default.aspx">

             <MediaElement Source="http://foo.com/MyVideo.wmv" Stretch="Uniform" />

     </HyperlinkButton>

    There are some great tutorials here in the getting started section. Those will help explain the concept of a content control (which HyperlinkButton is), so the syntax will make more sense. For now, just understand that the hyperlinkbutton can contain just about anything you can mark up in xaml: images, video, other buttons, etc.

    The model is quite different from asp.net, but almost identical to that of WPF.

    Pete

    Tuesday, January 6, 2009 7:43 PM
  •  Why can't i use this code

    HtmlPage.Window.Navigate(new Uri("my.domain.com/default1.aspx", UriKind.Absolute));
     Its giving syntax error. Here is my code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;


    namespace PageSwitch
    {
    public partial class MainPage : UserControl
    {
    public MainPage()
    {
    InitializeComponent();
    Generate.Click += new RoutedEventHandler(Generate_Click);
    }

    void Generate_Click(object sender, RoutedEventArgs e)
    {
    // giving problem here
    html. // can't find anything related to htmlpage
    }

    }

    }

    All i'm trying to do is generate a new window when a button is clicked

    I'm a novice to silverlight so pardon me if this is a stupid question

    Sunday, February 21, 2010 11:16 AM