Foreground color of an image is changing to white when I click/press the ImageButton

5 posts, 1 answers
  1. rajeev
    rajeev avatar
    4 posts
    Member since:
    Apr 2014

    Posted 01 May 2014 Link to this post

    Hi,

    I am assigning an image to imagebutton as RestStateImageSoure and setting Foreground color to Black. When I launch the App, it showing image in back color correctly. But when I press/hold the button, Image color is changing to white. How to change this behavior.

    Thanks in advance
  2. Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    661 posts

    Posted 06 May 2014 Link to this post

    Hi,

    In this case you can redefine the PressedStateWithOpacityMaskForegroundFillBrush named brush that controls this behavior.

    Let me know if this helps.

    Regards,
    Ivaylo Gergov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. rajeev
    rajeev avatar
    4 posts
    Member since:
    Apr 2014

    Posted 12 May 2014 in reply to Ivaylo Gergov Link to this post

    Hi Ivaylo Gergov,

    Thanks for your reply.

    Could you explain how to define this. I have tried but couldn't find anything like "PressedStateWithOpacityMaskForegroundFillBrush ".

    My code in .xaml:

    <tp:RadImageButton  Background="{StaticResource PhoneColor}" x:Name="imgMobile" ButtonShape="Ellipse" ButtonType="Custom" RestStateImageSource="/Assets/Icons/Mobile_D.png" Foreground="Black"   Width="150" Height="150" />

    in MainPage.cs:

             if (DeviceNetworkInformation.IsCellularDataEnabled)
                {
                    imgMobile.RestStateImageSource = new BitmapImage(new Uri("/Assets/Icons/Mobile_E.png", UriKind.Relative));
                    imgMobile.Foreground = new SolidColorBrush(Colors.White);
                }
                else
                {
                    imgMobile.RestStateImageSource = new BitmapImage(new Uri("/Assets/Icons/Mobile_D.png", UriKind.Relative));
                    imgMobile.DisabledStateImageSource = new BitmapImage(new Uri("/Assets/Icons/Mobile_D.png", UriKind.Relative));
                    imgMobile.Foreground = new SolidColorBrush(Colors.Black);
                }
    Where I need to implement your changes?












  5. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 13 May 2014 Link to this post

    Hi,

    You need to extract the template of the control by right-clicking it in Visual Studio's designer and choosing Edit Template -> Edit a Copy. This will extract the default style and you will be able to locate the PressedStateWithOpacityMaskForegroundFillBrush and change its value.

    I hope this information helps.

    Regards,
    Todor
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. rajeev
    rajeev avatar
    4 posts
    Member since:
    Apr 2014

    Posted 14 May 2014 in reply to Todor Link to this post

    Thanks  Todor & Ivaylo Gergov

    It solved my issue.
Back to Top
DevCraft banner