Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding on Brush property of GeometryDrawing does't work #18149

Open
yll690 opened this issue Feb 8, 2025 · 3 comments
Open

Binding on Brush property of GeometryDrawing does't work #18149

yll690 opened this issue Feb 8, 2025 · 3 comments

Comments

@yll690
Copy link
Contributor

yll690 commented Feb 8, 2025

Describe the bug

I create a Binding on Brush property of GeometryDrawing. However when the property in viewmodel changes, the drawing's color does not change.
I'm using Avalonia 11.2.3, .Net 8.0 and Window 11.

To Reproduce

Create a new project like this. After clicking the ChangeBackground Button, the TextBlock changes to Red while the GeometryDrawing remains blue.

AvaloniaApplication.zip

Image

  <StackPanel>
    <Button HorizontalAlignment="Center" Content="ChangeBackground" Command="{Binding ChangeBackground}"/>
    <TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <TextBlock Text="{Binding Background}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <Image Width="100" Height="100">
      <Image.Source>
        <DrawingImage>
          <DrawingImage.Drawing>
            <GeometryDrawing Brush="{Binding Background}" Geometry="M0,0 h100 v100 h-100 v-100"/>
          </DrawingImage.Drawing>
        </DrawingImage>
      </Image.Source>
    </Image>
  </StackPanel>
public partial class MainViewModel : ViewModelBase
{
    public string Greeting => "Welcome to Avalonia!";

    private IBrush background=Brushes.Blue;
    public IBrush Background { get => background; set => SetProperty(ref background, value); }


    public void ChangeBackground()
    {
        if (Background == Brushes.Blue)
            Background = Brushes.Red;
        else
            Background = Brushes.Blue;
    }
}

Expected behavior

No response

Avalonia version

11.2.3

OS

Windows

Additional context

No response

@yll690
Copy link
Contributor Author

yll690 commented Feb 8, 2025

If I resize the window, the drawing will turn red.

@yll690
Copy link
Contributor Author

yll690 commented Feb 8, 2025

Currently I'm trying to find all Image control and call InvalidateVisual method on them when the specific propery changed (or do it regularly in timer). It works, however I also worry about the performance.

@rabbitism
Copy link
Contributor

rabbitism commented Feb 8, 2025

should be duplcate with #8767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants