I have a custom textblock that has various text properties for left, right and same text as dependency properties. I use “Run” for making them have different foreground colors. It was like this in a method inside the control:
Inlines.Add(new Run(_leftValue[i]) { Foreground = Brushes.Red });
I added a dependency property for brush. How can I set it in my custom control’s cs file?
Thanks in advance
You have given us precious little to go on, but I’ll give you an answer anyway. The format for setting a dependency proeprty is this:
so for the example of a DP taking a brush, this should so it:
Note that
MyCustomControlis the literal name of your type, andthisshould be castable to a DependencyObject (if your control derives from Window, Control, FrameworkElement, etc. then it derives from DependencyObject).