VincentH-Net / CSharpForMarkup

Concise, declarative C# UI markup for .NET browser / native UI frameworks
MIT License
748 stars 43 forks source link

Support VisualStateManager #22

Open VincentH-Net opened 2 years ago

VincentH-Net commented 2 years ago

Is there no support for VisualStateManager?

image

Originally posted by @YegorStepanov in https://github.com/VincentH-Net/CSharpForMarkup/issues/19#issuecomment-1000878827

VincentH-Net commented 2 years ago

The C# API for VSM is mostly implemented, although there is still some polishing todo. There is still an issue to getting an example working.

Example:

    static ControlTemplate LikeButton => ControlTemplate(() =>
        Grid (
            Rectangle().Name("RedRectangle"),
            ContentPresenter().Center()
        )  .VisualStateGroups(
                VisualStateGroup("CheckStates",
                    VisualState("Checked", Storyboard(DoubleAnimation(0.1, 1.0, 0.5).Storyboard_TargetName("RedRectangle").Storyboard_TargetProperty("Opacity"))),
                    VisualState("Unchecked"),
                    VisualState("Indeterminate")
                )
            ), typeof(ToggleButton)
    );
VincentH-Net commented 1 year ago

At the moment the Windows App SDK (1.4) does not expose the necessary API's to C# to use VisualStateManager. A key blocker is that no x:Name can be set from C# - see this Windows App SDK discussion

A workaround for C# Markup for WinUI and Uno is to use VisualStateManager from a XAML resource - see this example C# Markup, which uses this XAML resource to animate a Button using the VisualStateManager