none
Default color of a button RRS feed

  • Question

  • Hello,
    What is the default color of a button inWPF?

    I am changing the color of a button button is clicked, and i want to refill with the default color when other button is clicked. similar to tab control.
    I am doing this with code behind. 
    But i cannot findout the default color.

    With regards,


    its me
    Wednesday, July 22, 2009 6:22 AM

Answers

  • Hi,

    One workaround would be before changing the button color,get the current background color,and hold a reference of it globally.When you want to revert back you can do that from this.

    Or you can find the default color of the button.Put a breakpoint,and find the current color before changing the background.You can get the brush details from the watch window.Create a brush similar to that and use it

    I tried finding it in SystemColors ,but couldnt find.

    Hope it helps
    FEAR NOT TO BE JUST Please mark posts as answers/helpful if it answers your query
    • Marked as answer by Watashi_me Thursday, July 23, 2009 12:00 AM
    Wednesday, July 22, 2009 7:45 AM

All replies

  • Hi,

    One workaround would be before changing the button color,get the current background color,and hold a reference of it globally.When you want to revert back you can do that from this.

    Or you can find the default color of the button.Put a breakpoint,and find the current color before changing the background.You can get the brush details from the watch window.Create a brush similar to that and use it

    I tried finding it in SystemColors ,but couldnt find.

    Hope it helps
    FEAR NOT TO BE JUST Please mark posts as answers/helpful if it answers your query
    • Marked as answer by Watashi_me Thursday, July 23, 2009 12:00 AM
    Wednesday, July 22, 2009 7:45 AM
  • Thank you for the reply.

    Logically your suggestion should work, but practically it is not working.

    I tried both methods, and result with breakpoint is bit close to the default.
    This is how my code look

    //I put breakpoint here to get the background value (value i got is "#FFECE9D8"
    System.Windows.Media.Brush myBrush = btn.Background;


    //So i convert that value into System.Windows.Media.Brush and assign that value to button
    System.Windows.Media.BrushConverter conv = new System.Windows.Media.BrushConverter();
    btn.Background = conv.ConvertFromString("#FFECE9D8") as System.Windows.Media.LinearGradientBrush;

    Am i doing anything wrong here.

    With regards,


     

    its me
    Wednesday, July 22, 2009 8:59 AM
  • Hi,

    See this code
     Dim obj As LinearGradientBrush
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
            obj = Button1.Background
            Button1.Background = Brushes.Blue
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
            Button1.Background = obj
        End Sub
    Hope it helps
    FEAR NOT TO BE JUST Please mark posts as answers/helpful if it answers your query
    • Proposed as answer by Rahul P Nath Saturday, July 25, 2009 7:26 AM
    Wednesday, July 22, 2009 2:07 PM