M
M
Michael2015-09-25 12:26:09
WPF
Michael, 2015-09-25 12:26:09

WPF color assignment?

There is a Border element whose color needs to be changed. How to give it the value #FF3399FF ? (not in XAML)
There is a second way: create the color yourself in the constructor, but then how to assign it in the code?
e1a2ce4b1ffe4ae49a92743b19f1a3bb.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tex0, 2015-09-25
@tex0

There is a second way: create the color yourself in the constructor, but then how to assign it in the code?

Border has a Background property. This is a property of type Brush. You create a property of type Brush in the class, bind to it in XAML, and define this property in the constructor as you like. XAML
example :
...
   <Border Background={Binding BorderBrush} />
...

behavior:
class MyControl
{
   public MyControl()
   {
       BorderBrush = new SolidColorBrush(youColor);//youColor - создаете свой цвет классом Color.
   }
   public Brush BorderBrush {get; private set;}
}

try like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question