Xamarin.Forms 3.4.0: Say Hello to ImageButton

Paul DiPietro

As part of our long-term goal to have more frequent releases, we’re pleased to announce the release of Xamarin.Forms 3.4.0. As always, this release contains even more bug fixes and most notably, another new highly requested feature, an ImageButton!

ImageButton

The ImageButton is a new control which is functionally separate from a typical Button where the Image property is usually for displaying a small icon next to the Button’s text. Implementing the button is straightforward, as you might expect:

<ImageButton Source="xamagon.png" 
            BackgroundColor="Transparent"
            WidthRequest="300"
            HeightRequest="300"
            FlexLayout.AlignSelf="Center"
            FlexLayout.Grow="1"
            Clicked="ImageButton_Clicked"
            Aspect="AspectFit">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal">
                <VisualState.Setters>
                    <Setter Property="Scale" Value="1"/>
                </VisualState.Setters>
            </VisualState>

            <VisualState x:Name="Pressed">
                <VisualState.Setters>
                    <Setter Property="Scale" Value="0.8"/>
                </VisualState.Setters>
            </VisualState>

        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</ImageButton>

In the above example, you set an image in the same way as on an Image using the Source property which takes any ImageSource, and you can now add a handler for the Clicked event. Using the VisualStateManager introduced in Xamarin.Forms 3.0, you can do things such as change the scale of the button when pressed. The result:

 

 

ImageButton also supports Command and CommandParameter for easily binding to a ViewModel or other binding context.

Get Started Today!

Check out the full release notes for all of the details and we encourage you to explore the documentation. Xamarin.Forms 3.4.0 includes more than 40 bug fixes and ships less than a month after 3.3.0, giving you more improvements at an even quicker pace.

This update is now available on NuGet via the Visual Studio package manager. The new ImageButton control can also be seen in action in The Little Things Playground.

Find a new issue or have a suggestion?

We invite everyone to engage with us on GitHub to report any new issues or make suggestions.

To find out what we are working on right now, explore our sprint project boards on GitHub. Finally, if you’re curious about what comes next and want to help us shape Xamarin.Forms, visit the Xamarin.Forms Feature Roadmap and let us know what you think!

Discuss this post in the Xamarin forums.

0 comments

Discussion is closed.

Feedback usabilla icon