We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

"ImageButton" Change backround image on pressed

Thread ID:

Created:

Updated:

Platform:

Replies:

149098 Nov 14,2019 11:08 AM UTC Nov 19,2019 01:13 PM UTC Xamarin.Forms 3
loading
Tags: SfButton
Ulf J
Asked On November 14, 2019 11:09 AM UTC

Hi!

I would like the same behavior as an ImageButton, the button should just show an image and when pressed I would like to change the image to another one.. so I tried the following code, but it does not work. Any tips how to make this work?


<syncfusion:SfButton x:Name="iconButton"
                        IsCheckable="False"
                        BorderWidth="0"
                        BackgroundColor="Transparent" 
                        PressedBackgroundColor="Transparent">
    <syncfusion:SfButton.Content>
        <Image Source="Test1.png" 
                HorizontalOptions="Center" 
                VerticalOptions="Center"/>
    syncfusion:SfButton.Content>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Pressed" >
                <VisualState.Setters>
                    <Setter Property="Content">
                        <Image Source="Test2.png" 
                                HorizontalOptions="Center" 
                                VerticalOptions="Center"/>
                    Setter>
                VisualState.Setters>
            VisualState>
            <VisualState x:Name="Normal">
                <VisualState.Setters>
                    <Setter Property="Content">
                        <Image Source="Test1.png" 
                                HorizontalOptions="Center" 
                                VerticalOptions="Center"/>
                    Setter>
                VisualState.Setters>
            VisualState>
        VisualStateGroup>
    VisualStateManager.VisualStateGroups>
syncfusion:SfButton>

Geetha Rajendran [Syncfusion]
Replied On November 15, 2019 01:06 PM UTC

Hi Ulf, 
  
Greetings from Syncfusion. 
  
We would like to let you know that your requirement “Having different image on press and normal state on SfButton” has been achieved by setting the ImageSource property of SfButton. By default, we have property to show the Image with help of ShowIcon and ImageSource properties as per in below code example 
  
Code Example [XAML]: 
  
<buttons:SfButton ShowIcon="True" 
                ImageSource="Normal.png"> 
    <VisualStateManager.VisualStateGroups> 
        <VisualStateGroup x:Name="CommonStates"> 
            <VisualState x:Name="Pressed" > 
                <VisualState.Setters> 
                    <Setter Property="ImageSource" Value="Pressed.png"> 
                    </Setter> 
                </VisualState.Setters> 
            </VisualState> 
            <VisualState x:Name="Normal"> 
                <VisualState.Setters> 
                    <Setter Property="ImageSource" Value="Normal.png"> 
                    </Setter> 
                </VisualState.Setters> 
            </VisualState> 
        </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 
</buttons:SfButton> 
 
Please download the prepared sample in below link 
  
  
Please let us know if you have any other concern. 
 
Thanks, 
Geetha R 


Ulf J
Replied On November 18, 2019 09:21 AM UTC

Hi!

Thank for the fast reply!

The example works but it displays an icon inside the button, I would like the image to become the complete button,

This shows the the result: Big image is from the example I posted (where pressed and normal is not working, but the image is displayed correct)  the smaller image is from your example (it works when it comes to changed image on press and release, but I would like the image look like the left one), the image must become the complete button as an ImageButton works. How can I do that?



Thanks
Ulf

Hemalatha Marikumar [Syncfusion]
Replied On November 19, 2019 01:13 PM UTC

Hi Ulf, 
 
Thanks for your update. 
 
If your requirement to fill only the provided image with overall button then, it has been achieved with the help of setting BackgroundImage property itself as per in below code snippet 
  
Code snippet [XAML] 
<buttons:SfButton BackgroundImage="Normal.png"                          
                   HorizontalOptions="Center" 
                   HeightRequest="40" 
                   WidthRequest="40" 
                   VerticalOptions="Center"> 
     <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="CommonStates"> 
             <VisualState x:Name="Pressed" > 
                 <VisualState.Setters> 
                     <Setter Property="BackgroundImage" Value="Pressed.png"> 
                     </Setter> 
                 </VisualState.Setters> 
             </VisualState> 
             <VisualState x:Name="Normal"> 
                 <VisualState.Setters> 
                     <Setter Property="BackgroundImage" Value="Normal.png"> 
                     </Setter> 
                 </VisualState.Setters> 
             </VisualState> 
         </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 
</buttons:SfButton> 
  
Please get back to us if you need any further assistance on this. 
  
Regards, 
Hemalatha M. 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon