xamarin.forms - Sliding information box in bottom

2019-08-25 01:58发布

I am learning xamarin.forms technology.What mean by title is that I want to make sliding information box (from bottom, left or right side of the screen). Everything should be in the bottom of the page/view. Also placing in bottom something in xamarin.forms is also petty tricky.

Slides

I want to do this instead of dialog, because I dont want to feeze ui when alert dialog pop and i dont want force an user to click anything

Could you guys show me how can I do that?

2条回答
▲ chillily
2楼-- · 2019-08-25 02:39

You should use AbsoluteLayout for this, there goes an example:

// ContentPage:

var layout = new StackLayout {
 // you page content
};

Content = new NotifyLayoutView(layout);

And view class:

public class NotifyLayoutView : AbsoluteLayout
{
   public NotifyLayoutView(View content)
   {
        var flash = new StackLayout
        {
            BackgroundColor = Color.Red,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Children = {
               new Label { Text = "My notification" }
            }
        };

        SetLayoutFlags(content, AbsoluteLayoutFlags.All);
        SetLayoutBounds(content, new Rectangle(0f, 0f, 1f, 1f));
        SetLayoutFlags(flash, AbsoluteLayoutFlags.WidthProportional | 
        AbsoluteLayoutFlags.PositionProportional);
        SetLayoutBounds(flash, new Rectangle(0.5, 0.99, 0.95, AutoSize));
        Children.Add(content);
        Children.Add(flash);
   }
}

To change flash visibility you can use:

// open
await flash.ScaleTo(1.0f, 100);
await flash.FadeTo(1.0f, 100);

// hide
await layout.ScaleTo(0.0f);
await layout.FadeTo(0.0f);
查看更多
迷人小祖宗
3楼-- · 2019-08-25 02:42
登录 后发表回答