adospace / reactorui-maui

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

Is it possible to use Behavior? #169

Closed cris-m closed 11 months ago

cris-m commented 11 months ago

I would like to know if there is a ways to use Behavior. Like to change color of svg image using IconTintColorBehavior of .NET MAUI Community Toolkit

Originally posted by @cris-m in https://github.com/adospace/reactorui-maui/issues/14#issuecomment-1793655239

adospace commented 11 months ago

The latest version of MauiReactor supports natively behaviors:

[Scaffold(typeof(CommunityToolkit.Maui.Behaviors.IconTintColorBehavior))]
partial class IconTintColorBehavior { }

class BehaviorTestPageState
{
    public Color Color { get; set; } = Colors.Red;
}

class BehaviorTestPage : Component<BehaviorTestPageState>
{
    public override VisualNode Render()
    {
        return new ContentPage()
        {
            new VStack(spacing: 10)
            {
                new Image("shield.png")
                {
                    new IconTintColorBehavior()
                        .TintColor(State.Color)
                },

                new HStack(spacing: 5)
                {
                    new Button(nameof(Colors.Red), () => SetState(s => s.Color = Colors.Red)),
                    new Button(nameof(Colors.Green), () => SetState(s => s.Color = Colors.Green)),
                    new Button(nameof(Colors.Black), () => SetState(s => s.Color = Colors.Black)),
                }
                .HCenter()
            }
            .Center()
        };
    }
}
adospace commented 11 months ago

https://adospace.gitbook.io/mauireactor/deep-dives/behaviors