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.

Changing color of SolidColorBrush don't cause a rerender

See original GitHub issue

Describe the bug When i change Color property of SolidColorBrush in resources it doesn’t cause a rerender. It works in 11-preview*, but doesn’t work in rc1-1

To Reproduce Steps to reproduce the behavior:

  1. App.axaml:
<Application.Resources>
    <SolidColorBrush x:Key="MyBrush" Color="Aqua"></SolidColorBrush>
</Application.Resources>
  1. Window:
<StackPanel>
  <TextBlock Foreground="{DynamicResource MyBrush}">TEST TEXT</TextBlock>
  <Button Foreground="{DynamicResource MyBrush}" Click="Button_OnClick">CHANGE COLOR</Button>
  <Button Foreground="{DynamicResource MyBrush}">DUMMY</Button>
</StackPanel>
  1. Code behind:
private void Button_OnClick(object? sender, RoutedEventArgs e) {
    var solidColorBrush = App.Current.Resources["MyBrush"] as SolidColorBrush;
    var random = new Random();
    solidColorBrush.Color = Color.FromRgb((byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255));
}

e138723d-ab24-444d-9a71-e9d02e862599

Desktop (please complete the following information):

  • Version: 11.0.0-rc1.1

Fast repro (also contains my other code, don’t mind): AvaloniaApplication1.zip

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Reactions:1
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
workgroupengineeringcommented, Jun 6, 2023

if you change the code like this

        private void Button_OnClick(object? sender, RoutedEventArgs e)
        {
            var random = new Random();
            App.Current!.Resources["MyBrush"] = new SolidColorBrush()
            {
                Color = Color.FromRgb((byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255))
            };
        }

works.

1reaction
SKProCHcommented, Jun 6, 2023

Yes, i think it related to your issue, @danipen

But i facing this issue only for rc1-1, not for preview*. I should check it again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the color of a SolidcolorBrush resource with ...
This will change the background color based on the text value; if text is white, then the background is white, black, then background...
Read more >
How to change the LineSeries2D.Brush color at runtime
My problem is that the chart does not update when I change the series brush color . How do I force a redraw?...
Read more >
Best way to cache theme resources to avoid dynamic ...
We would like to bind the color values of our solid color resource brushes to the colors of brushes in your theme libraries....
Read more >
Force Refresh() not working? - NinjaTrader Support Forum
The color of the plot corresponds to the label. As you can see the ForceRefresh() never makes the changes. Is there something I...
Read more >
How can I change a svg image's color
Hi, I want to use a svg image as a SimpleButton's Glyph, and set it's foreground color blue. when I move mouse over...
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