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

CanvasVirtualControl inside Grid will refuse to redraw at a certain position #962

Open
fourst4r opened this issue Aug 24, 2024 · 0 comments

Comments

@fourst4r
Copy link

fourst4r commented Aug 24, 2024

Minimal reproducible: canvasvirtualtest.zip
Video: https://github.com/user-attachments/assets/84db3fdb-cc68-40d3-a464-2a4b675030cd

I could only get this to happen with a CanvasVirtualControl inside a Grid with multiple areas. I'm not sure what triggers it to stop redrawing, but the RegionsInvalidated callback just stops getting fired altogether until you size it back down again.

Xaml:

<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="canvasvirtualtest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:canvasvirtualtest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
    mc:Ignorable="d">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Button Grid.Column="0">BUDDON!</Button>
        <canvas:CanvasVirtualControl x:Name="cvc" Grid.Column="1" RegionsInvalidated="CanvasVirtualControl_RegionsInvalidated"/>
    </Grid>
</Window>

CS:

using Microsoft.Graphics.Canvas.UI.Xaml;
using Microsoft.UI.Xaml;
using System;
using Windows.UI;

namespace canvasvirtualtest;

public sealed partial class MainWindow : Window
{
    private DispatcherTimer _timer;

    public MainWindow()
    {
        this.InitializeComponent();
        _timer = new DispatcherTimer();
        _timer.Interval = TimeSpan.FromSeconds(0.5);
        _timer.Tick += (_,_) => cvc.Invalidate();
        _timer.Start();
    }

    private void CanvasVirtualControl_RegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args)
    {
        foreach (var region in args.InvalidatedRegions)
        {
            using var ds = sender.CreateDrawingSession(region);
            var color = Color.FromArgb(
                0xff, 
                (byte)Random.Shared.Next(0xff), 
                (byte)Random.Shared.Next(0xff), 
                (byte)Random.Shared.Next(0xff));
            ds.Clear(color);
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant