question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Binding SolidColorBrush.Color in a control template yields binding error

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
billhenncommented, Oct 18, 2022

@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!

1reaction
lukaszossowskicommented, Oct 18, 2022

I would highly suggest that messages like this only be written to the Output if there is a legit issue.

This is particularly important, because apart from visual clutter, it makes it much harder to spot actual binding errors that are displayed there.

More context: #9219 (comment)

Wouldn’t it be possible to filter the messages? They do seem to all contain

'Null value in expression '{empty}'

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found