none
Change hyperlink color from code behind RRS feed

Answers

  • You juste change link foreground color like that :

    <StackPanel>
                 <TextBlock>
                 <Hyperlink x:Name="link" NavigateUri="http://www.microsoft.com">
                     View MS site !
                 </Hyperlink>
            </TextBlock>
            
            <Button Content="Change link colo" Click="Button_Click"/>
           
            </StackPanel>
    And in code behind :

     private void Button_Click(object sender, RoutedEventArgs e)
            {
                Random r = new Random();
    
                Color newColor = Color.FromRgb(
                    Convert.ToByte(r.Next(0, 255)),
                    Convert.ToByte(r.Next(0, 255)),
                    Convert.ToByte(r.Next(0, 255)));
    
                link.Foreground = new SolidColorBrush(newColor);
            }






    http://slouge.wordpress.com
    • Proposed as answer by Rahul P Nath Tuesday, November 3, 2009 7:05 AM
    • Marked as answer by wpfdevelop Tuesday, November 3, 2009 5:58 PM
    Tuesday, November 3, 2009 6:56 AM

All replies

  • You juste change link foreground color like that :

    <StackPanel>
                 <TextBlock>
                 <Hyperlink x:Name="link" NavigateUri="http://www.microsoft.com">
                     View MS site !
                 </Hyperlink>
            </TextBlock>
            
            <Button Content="Change link colo" Click="Button_Click"/>
           
            </StackPanel>
    And in code behind :

     private void Button_Click(object sender, RoutedEventArgs e)
            {
                Random r = new Random();
    
                Color newColor = Color.FromRgb(
                    Convert.ToByte(r.Next(0, 255)),
                    Convert.ToByte(r.Next(0, 255)),
                    Convert.ToByte(r.Next(0, 255)));
    
                link.Foreground = new SolidColorBrush(newColor);
            }






    http://slouge.wordpress.com
    • Proposed as answer by Rahul P Nath Tuesday, November 3, 2009 7:05 AM
    • Marked as answer by wpfdevelop Tuesday, November 3, 2009 5:58 PM
    Tuesday, November 3, 2009 6:56 AM
  • Hi,
    You can also use the default colors available in Brushes .

    link.Foreground = Brushes.Red
    Hope it helps
    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
    Tuesday, November 3, 2009 7:05 AM