Skip to content
New issue

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

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

Already on GitHub? # to your account

Canvas Height Not Updating When ItemsSource Changes #150

Closed
Gummimundur opened this issue Jan 9, 2025 · 3 comments · Fixed by #151
Closed

Canvas Height Not Updating When ItemsSource Changes #150

Gummimundur opened this issue Jan 9, 2025 · 3 comments · Fixed by #151
Assignees

Comments

@Gummimundur
Copy link
Contributor

When binding to an ItemsSource, the content renders correctly initially. However, if the ItemsSource is updated, the height of the Canvas does not adjust to reflect the new content.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:draw="http://schemas.appomobi.com/drawnUi/2023/draw"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:sand="clr-namespace:Sandbox"
             x:DataType="{x:Type sand:SomeViewModel}"
             x:Class="Sandbox.SomePage"
             Title="SomePage">
    <ContentPage.BindingContext>
        <sand:SomeViewModel />
    </ContentPage.BindingContext>
    <ScrollView Padding="16">
        <VerticalStackLayout Background="Red">
            <draw:Canvas VerticalOptions="Center"
                         Background="White"
                         HorizontalOptions="Fill"
                         HardwareAcceleration="Enabled">
                <draw:SkiaLayout VerticalOptions="Center"
                                 HorizontalOptions="Fill"
                                 ItemsSource="{Binding Items}"
                                 Type="Wrap"
                                 Split="2">
                    <draw:SkiaLayout.ItemTemplate>
                        <DataTemplate x:DataType="{x:Type x:Int32}">
                            <draw:SkiaLabel Text="{Binding}"
                                            TextColor="Red"
                                            FontSize="48"
                                            Background="Green" />
                        </DataTemplate>
                    </draw:SkiaLayout.ItemTemplate>
                </draw:SkiaLayout>

            </draw:Canvas>

            <Button Command="{Binding UpdateItemsCommand}"
                    Grid.Row="1"
                    Text="Update Items" />
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>
using AppoMobi.Specials;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace Sandbox;

public partial class SomePage : ContentPage
{
    public SomePage() => InitializeComponent();
}

public partial class SomeViewModel : ObservableObject
{
    [ObservableProperty]
    private ObservableRangeCollection<int> items = [1, 2];

    [RelayCommand]
    public async Task UpdateItemsAsync()
    {
        this.Items.AddRange([2, 3, 4, 5]);

        await Task.Delay(TimeSpan.FromSeconds(3));

        this.Items.ReplaceRange(Enumerable.Range(0, 100).ToList());
    }
}
@taublast
Copy link
Owner

Hey thanks for reporting this, especially for repro! On it.

@taublast taublast self-assigned this Jan 10, 2025
@taublast
Copy link
Owner

Thanks for the PR, a new version is going to be out this weekend, stable skiasharp v3 for net9. With hardware acceleration for windows, a game changer for creating MAUI desktop apps. :)

@Gummimundur
Copy link
Contributor Author

Looking forward to it. Really enjoying this library, great work!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants