Binding SolidColorBrush.Color in a control template yields binding error
See original GitHub issueDescribe the bug
A binding error occurs when my custom templated control is first loaded when binding a SolidColorBrush.Color
to a styled property. The binding works fine after that.
To Reproduce
I have a basic control that inherits TemplatedControl
and has a Color
property on it:
public static readonly StyledProperty<Color> ColorProperty =
AvaloniaProperty.Register<ArcadeControlBase, Color>(nameof(Color), Colors.Transparent);
public Color Color {
get => GetValue(ColorProperty);
set => SetValue(ColorProperty, value);
}
In the control’s template:
<Rectangle Width="10" Height="10">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Color}" />
</Rectangle.Fill>
</Rectangle>
This yields an error in the VS Output tool window:
[Binding]Error in binding to '#00000000'.'Color': 'Null value in expression '{empty}' at '$self.TemplatedParent'.'(SolidColorBrush #59182880)
Expected behavior
There should be no binding error.
Desktop (please complete the following information):
- OS: Windows
- Version 11.0.0-preview2
Issue Analytics
- State:
- Created a year ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
SolidColorBrush Color binding issues
So i'm having some binding issues ATM with my "GroupColour" property on my ObjA class. I also have a CurrentState variable, which, based...
Read more >Data binding overview - WPF .NET
In the Create a binding section, the button is red because its Background property is bound to a string property with the value...
Read more >Data binding in depth - UWP applications
When using {x:Bind} in a data template, so that its bindings can be validated (and efficient code generated for them) at compile-time, the ......
Read more >change the rowstyle foreground color based on a data value
I am trying to change the row style using a converter however if use the code below i get the wonderful error AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR...
Read more >Flexible and Powerful Data Binding with WPF, Part 2
WPF draws the error border in a special area, called the Adorner layer, which is the last layer drawn (highest Z-Order) by the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@maxkatz6 thank you for the additional information. I come from WPF and am new to Avalonia. This really threw me off for a half hour trying to figure out if I was doing something wrong before posting.
I would highly suggest that messages like this only be written to the Output if there is a legit issue. I (and most devs) try to keep my Output completely clean so that I can clearly identify when there are problems I need to address. It’s really distracting to see the Output get clogged up with a ton of these messages, and makes it harder to identify real problems.
Considering how many others have reported similar things, hopefully that’s an indication that some kind of suppression of this message is needed. Appreciate it!
This is particularly important, because apart from visual clutter, it makes it much harder to spot actual binding errors that are displayed there.
Wouldn’t it be possible to filter the messages? They do seem to all contain
'Null value in expression '{empty}'