locked
Changing Link Color RRS feed

  • Question

  • Hi,
    i added a simple hyperlink to my application. Implemented like described in the MSDN Help:

    <TextBlock TextWrapping="Wrap"
      <Run Text="Click "/> 
      <Hyperlink Click="OnClick"
        <Run Text="here"/> 
      </Hyperlink> 
      <Run Text=" for more information"/> 
    </TextBlock> 

    Visual Studio:

    private void OnClick(object sender, RoutedEventArgs e) 
        try 
        { 
    System.Diagnostics.Process.Start("http://www.microsoft.com"); 
        } 
        catch {} 


    OK, that works and i have a hyperlink. How can i change the colors of this link. At the moment
    the microsoft standard colors (blue, red (for overstate) doesn't match my design.


    :

    • Edited by Bee Dee Monday, November 24, 2008 10:00 AM code input
    Monday, November 24, 2008 9:57 AM

Answers

  • Hi Bee Dee,

    Few ways I can think of to achieve this is to:

    1. Without code, use the Visual State Manager (which now also works for WPF as long as you download the WPF Toolkit), and set the MouseEnter and MouseLeave states of the TextBlock.

    2. Without code, WPF only, create one storyboard name it maybe tbMouseEnter, and set the foreground color of your TextBlock to blue (or any other color you want), create another storyboard, maybe naming it tbMouseLeave, and set the foreground color of the TextBlock to its original color. Then add 2 events (in the Interaction -> Trigger pane), select the TextBlock, and set the condition to the following:
    • When TextBlock1.MouseEnter is raised tbMouseEnter.Begin
    • When TextBlock1.MouseLeave is raised tbMouseLeave.Begin
    3. Using code, add an eventhandler for your TextBlock to handle the MouseEnter event, and when that event triggers, set the Foreground color of the TextBlock to any color you want. Also add a MouseLeave eventhandler to your Textblock, to set the Foreground color back to its original color.

    Gotta love the flexibility that WPF and Silverlight brings to the table. Hope this answers your question.

    -
    Tuesday, November 25, 2008 9:33 AM

All replies

  • Hi

    Just change the Foreground to the colour you want, e.g. for a green hyperlink:

    ...
     <TextBlock>
         <Run Text="Click "/>
         <Hyperlink Foreground="#FF2A9443" Click="OnClick">
         <Run Text="here"/>
         </Hyperlink>
         <Run Text=" for more information"/>
     </TextBlock>
    ...


    Cheers

    Carien
       
    Monday, November 24, 2008 12:02 PM
  • Great - thats easy ;-)

    Thanks...
    Tuesday, November 25, 2008 7:24 AM
  • Sorry, but thats not all ;-)

    Now the link is in the color i want, but the rollovercolor is gone. I think there
    must be an other way.



    :
    Tuesday, November 25, 2008 7:30 AM
  • Hi Bee Dee,

    Few ways I can think of to achieve this is to:

    1. Without code, use the Visual State Manager (which now also works for WPF as long as you download the WPF Toolkit), and set the MouseEnter and MouseLeave states of the TextBlock.

    2. Without code, WPF only, create one storyboard name it maybe tbMouseEnter, and set the foreground color of your TextBlock to blue (or any other color you want), create another storyboard, maybe naming it tbMouseLeave, and set the foreground color of the TextBlock to its original color. Then add 2 events (in the Interaction -> Trigger pane), select the TextBlock, and set the condition to the following:
    • When TextBlock1.MouseEnter is raised tbMouseEnter.Begin
    • When TextBlock1.MouseLeave is raised tbMouseLeave.Begin
    3. Using code, add an eventhandler for your TextBlock to handle the MouseEnter event, and when that event triggers, set the Foreground color of the TextBlock to any color you want. Also add a MouseLeave eventhandler to your Textblock, to set the Foreground color back to its original color.

    Gotta love the flexibility that WPF and Silverlight brings to the table. Hope this answers your question.

    -
    Tuesday, November 25, 2008 9:33 AM