How to remove the shadow of a button on Xamarin Forms

前端 未结 4 1369
猫巷女王i
猫巷女王i 2020-12-19 12:06

is it possible? I would like to remove the shadow of the buttons on Xamarin Forms.

Thanks

相关标签:
4条回答
  • 2020-12-19 12:36

    There's a simple hack around this. Simply wrap the button in a Frame element, with HasShadow set to False

    <Frame HasShadow="False" Padding="0" Margin="0">
        <Button Padding="15"
                Text="Log in"
                TextColor="Blue"
                FontSize="17" />
    </Frame>
    

    This will remove the button's shadow

    0 讨论(0)
  • 2020-12-19 12:51

    Explaining with more detail.

    using Android.App;
    using Android.Content.PM;
    using Android.OS;
    using Xamarin.Forms.Platform.Android;
    using ProjectName.Droid;
    using Xamarin.Forms;
    
    [assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(FlatButtonRenderer))]
    namespace ProjectName.Droid
    {    
        public class FlatButtonRenderer : ButtonRenderer
        {
            protected override void OnDraw(Android.Graphics.Canvas canvas)
            {
                base.OnDraw(canvas);
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-19 12:52

    @Tonatio in your renderer instead of using

    [assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(FlatButtonRenderer))]
    

    use this

    [assembly: ExportRenderer(typeof(YourCustomButton), typeof(FlatButtonRenderer))]
    

    you will have to make a CustomButton control that inherits from Xamarin.Forms.Button and then use that custom button in your xaml instead of regular button. that should do the thing

         //Add references to your custom control
            xmlns:controls="clr-namespace:YourNameSpace.Controls"
         //Use control
         <Grid>
               <controls:YourCustomButton x:Name="_customButton"/>
         </Grid>
    

    Feel free to drop by if you need some more help.

    0 讨论(0)
  • 2020-12-19 12:59

    For delete shadow on button Android you just need create a renderer in project Droid and set BackroundColor with transparent or other color.

    For a project using PCL :

    [assembly: ExportRenderer(typeof(Button),typeof(FlatButtonRenderer))]
    namespace Project.Droid
        {
            public class FlatButtonRenderer : ButtonRenderer
            {
                protected override void OnDraw(Android.Graphics.Canvas canvas)
                {
                    base.OnDraw(canvas);
                }
            }
        }
    

    In XAML :

    <Button BackgroundColor="Transparent" Text="ClickMe"/>
    
    0 讨论(0)
提交回复
热议问题