adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
587 stars 49 forks source link

CarouselView usage #38

Closed aokocax closed 1 year ago

aokocax commented 1 year ago

First of all, thanks for the great project. I can easily add simple controls into the project, but I have difficulties with controls that require initialization such as CarouselView. Could you please share sample code for CarouselView?

adospace commented 1 year ago

Hi, this should work just fine:

new CarouselView()
    .ItemsSource(Enumerable.Range(1, 10)
        .Select(_=>$"Item{_}"), _ => new Label(_))

essentially it's like other ItemsView-derived controls like CollectionView: you have to pass in the items source and a render method.

aokocax commented 1 year ago

Thank you for reply. It worked. Unfortunately, I couldn't assign an indicatorview this time.

This was how it could be done with Maui's own controls. var carouselView = new CarouselView() { ItemsSource = myItemsSource, ItemTemplate = myItemTemplate }; carouselView.IndicatorView = indicatorView;

adospace commented 1 year ago

ok, for it to work I need to change a thing on the library in the next version you'll able to add it too, please stay tuned :)

adospace commented 1 year ago

I've added a sample page in the test app that shows how to use the indicator view (you need to upgrade to latest version of MauiReactor):

new Grid("* 40", "*")
{
    new CarouselView(r => _carouselView = r)
        .ItemsSource(Enumerable.Range(1, 5), _=> new Label($"Page{_}").VCenter()),

    new IndicatorView(r =>
    {
        if (_carouselView != null)
        {
            _carouselView.IndicatorView = r;
        }
    })
    .HCenter()
    .VCenter()
    .IndicatorTemplate(() => new Label("Test"))
    .VisualState("CommonStates", "Normal", MauiControls.Label.TextColorProperty, Colors.Black)
    .VisualState("CommonStates", "Selected", MauiControls.Label.TextColorProperty, Colors.White)
    .GridRow(1),
}
aokocax commented 1 year ago

@adospace , you are great, thank you. You're going to have to convert my projects to MauiReactor :). This has been my favorite project for a long time. I also plan to make small contributions.