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's Size property becomes 0 after the window is maximized. #986

Open
RostislavMetroLab opened this issue Feb 21, 2025 · 0 comments

Comments

@RostislavMetroLab
Copy link

RostislavMetroLab commented Feb 21, 2025

If you create a stretched grid on the whole window with CanvasVirtualControl:

    <Grid HorizontalAlignment="Stretch"
      VerticalAlignment="Stretch">
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
      <Border
          Grid.Column="1"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch"
          Background="GreenYellow" />
      <win2d:CanvasVirtualControl
          x:Name="_canvasVirtualControl"
          Grid.Column="1"
          Width="200" />
    </Grid>

and draw something on the RegionsInvalidated event:

foreach (var region in args.InvalidatedRegions)
{
    IRandomAccessStream random =
        await RandomAccessStreamReference.CreateFromUri(new Uri("cake.png")).OpenReadAsync();

    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(random);
    PixelDataProvider pixelData = await decoder.GetPixelDataAsync();

    byte[] colorArray = pixelData.DetachPixelData();

    using (var canvasRenderTarget = new CanvasRenderTarget(sender, 200, 200, 96))
    {
        canvasRenderTarget.SetPixelBytes(colorArray);

        using (var drawingSession = sender.CreateDrawingSession(region))
        {
            drawingSession.DrawImage(canvasRenderTarget, 0, 0);
        }
    }
}

then after maximizing the window the CanvasVirtualControl.Size property becomes (0,0) and returns to the correct value after reducing the window size. UWP did not have this problem, but it appears in WinUI3. Is there any workaround?

Image

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