locked
How to set buttons background from code behind in xaml c# RRS feed

  • Question

  • Hello sir,

    I have a button within listbox control and at runtime i am able to find that button say btnClick now i need to assing background color of that particular button at runtime from code behind. How will i do this???

    How to assign buttons background color from code behind in xaml and c# metro apps????

    • Changed type Jie Bao Thursday, January 5, 2012 5:49 AM
    Wednesday, January 4, 2012 9:19 AM

Answers

  • First you need to create a brush or get it from the resources. For example:

    var myBrush = new SolidColorBrush(ColorHelper.FromArgb(255, 127, 127, 127));
    
    


    And then use this brush:

    button.Background = myBrush;
    
    



    • Proposed as answer by Jie Bao Thursday, January 5, 2012 5:50 AM
    • Marked as answer by Shambhu mishra Thursday, January 5, 2012 7:18 AM
    Wednesday, January 4, 2012 12:33 PM