Results 1 to 6 of 6

Thread: [RESOLVED] Why does Mouse Down not function?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2008
    Posts
    159

    Resolved [RESOLVED] Why does Mouse Down not function?

    Hello,

    I am new to WPF, so bare with me here. I an attempting to create a hyperlink that launches a webpage. Here is my code.

    Code:
    <TextBlock Margin="352.5,0,356,232.54" VerticalAlignment="Bottom" TextWrapping="Wrap" MouseLeftButtonDown="Test_Click">
    			<Hyperlink>Click Here</Hyperlink>
    		</TextBlock>
    And here is the code behind.

    Code:
    private void Test_Click(object sender, RoutedEventArgs e)
    		{
    			System.Diagnostics.Process.Start("http://www.msn.com");
    		}
    It doesn't do anything when I click down on the mouse... Am I missing something here?

    What is the best method for doing hyperlinks? I have created a button template for a hyperlink and can get it to work this way, but I really didn't want a template for each hyperlink I want...

    Any direction or help is greatly appreciated!

  2. #2
    Lively Member
    Join Date
    Oct 2005
    Posts
    89

    Re: Why does Mouse Down not function?

    Hey there csleech,

    Here's some XAML code for using hyperlink control directly:

    Code:
        <Hyperlink NavigateUri="http://www.msn.com">
            Click Here
        </Hyperlink>
    Hope this helps... Shweet

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2008
    Posts
    159

    Re: Why does Mouse Down not function?

    Hey spike,

    The problem with that code is that it doesn't automatically start IE (or whatever the default browser is) and load the webpage. This was the original need for a mouse event, but those aren't working for some reason... I've worked around this by just creating a button template.

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Re: Why does Mouse Down not function?

    Hi.

    Try using the PreviewMouseLeftButtonDown instead.

    I have found that MouseDown, MouseLeftButtonDown etc. doesn't always work.
    I think it's because a previous handler has set the e.Handled=true, which stops the event from bubbling further up.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2008
    Posts
    159

    Re: Why does Mouse Down not function?

    Pax.... THANKS!!!! That worked great! Not sure why you have to use the Preview portion but I'll take it! That is much simplier than having to create a button template for everything.

  6. #6
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Re: [RESOLVED] Why does Mouse Down not function?

    You're welcome
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width