Xamarin Forms: StackLayout with rounded corners

后端 未结 6 1296
故里飘歌
故里飘歌 2020-12-24 10:39

I am developing an app using Xamarin Forms PCL. I need a StackLayout with rounded corners. I have tried frame as well for rounded corner container but there is no corner rad

相关标签:
6条回答
  • 2020-12-24 11:09

    You can use Frame and put StackLayout inside , Note Frame take padding 20 by default :

    <Frame CornerRadius="10"  
           OutlineColor="Red" 
           Padding="0">
                <StackLayout>
    
                </StackLayout>
    </Frame>
    
    0 讨论(0)
  • 2020-12-24 11:10

    You can set rounded corner for any Layout or View or Cell (StackLayout, Grid, ListView)

    http://venkyxamarin.blogspot.in/2017/12/how-to-set-corner-radius-for-view.html#more

    0 讨论(0)
  • 2020-12-24 11:22

    Since Xamarin has released Effects mechanism, it now can be done by implementing a custom effect on both platforms. An advantage of this approach is that effects are more light-weight, reusable and can be parameterized and applied to any UI element.

    After you create a custom RoundCornersEffect inheriting RoutingEffect, declare a CornerRadius attached property and implement PlatformEffect on each platform, it can be applied to any Xamarin.Forms layout or control like this:

    <StackLayout effects:RoundCornersEffect.CornerRadius="48"/>
    

    with hardcoded corners radius or a value from resources

     <BoxView effects:RoundCornersEffect.CornerRadius="{StaticResource LargeCornerRadius}" /> 
    

    Here is a link to full implementation and usage examples.

    0 讨论(0)
  • 2020-12-24 11:23
    <!--Curved stack-->
    <Frame CornerRadius="5" 
               HorizontalOptions="Center" 
               VerticalOptions="Start"
               HasShadow="True"
               IsClippedToBounds="True"
               Padding="0">
            <StackLayout Padding="10,5,10,5"   
                             Orientation="Horizontal" 
                             BackgroundColor="White"  >
                <Image Source="settingsIcon"  
                       HeightRequest="25" 
                       WidthRequest="25" 
                       Aspect="Fill" />
                <Label Text="Filter" 
                       FontSize="Medium" 
                       VerticalTextAlignment="Center" 
                       VerticalOptions="Center"/>
            </StackLayout>
        </Frame>
    

    I just tried to copy BigBasket's filter buttons. See How cool it looks

    0 讨论(0)
  • 2020-12-24 11:25

    I recently had the same need, so I created a Custom Renderer for both iOS and Android. I released it as a Nuget which you can find here. The source code is available on GitHub, and here is a little "How-To"

    Hope this helps! It is very easy to use (Same as a ContentView, which it is at it's base), although note this is compile for .NET Standard, but you can also pull the code into your PCL

    0 讨论(0)
  • 2020-12-24 11:35

    Use following to achieve your expected output;

    Xamarin Forms control: https://github.com/nitescua/Xamore/blob/master/Xamore.Controls/Border.cs

    iOS: https://github.com/nitescua/Xamore/blob/master/Xamore.Controls.iOS/Renderers/BorderRenderer.cs

    Android: https://github.com/nitescua/Xamore/blob/master/Xamore.Controls.Droid/Renderers/BorderRenderer.cs https://github.com/nitescua/Xamore/blob/master/Xamore.Controls.Droid/Renderers/BorderRendererVisual.cs (Note some files in https://github.com/nitescua/Xamore/tree/master/Xamore.Controls.Droid/Renderers have compilation set to None, I was doing some tests, need to remove those)

    WinPhone: https://github.com/nitescua/Xamore/blob/master/Xamore.Controls.WinPhone/Renderers/BorderRenderer.cs

    0 讨论(0)
提交回复
热议问题