简体   繁体   English

Xamarin形式:ContentPage OnCreate事件?

[英]Xamarin Forms: ContentPage OnCreate event?

I'm creating a messaging app, and I need that when I enter the messaging thread with someone, message bubbles show inside the layout. 我正在创建一个消息传递应用程序,当我与某人一起进入消息传递线程时,需要在布局内显示消息气泡。 I'm doing this easily using: 我很容易使用以下方法做到这一点:

MyMessageThreadStackLayout.Children.Add(
// Message bubble building logic goes here
);

But currently, I'm putting this inside the: 但目前,我将其放入:

protected override void OnAppearing ()

But this makes my elements appear after the content page animation is shown making it look really weird. 但这使我的元素在显示内容页面动画之后出现,使其看起来真的很奇怪。 Is there a OnCreate event that can let me load the messages into the view before showing them with the animation? 是否有一个OnCreate事件可以让我在将消息与动画一起显示之前将消息加载到视图中? Thank you 谢谢

You could use the protected virtual void LayoutChildren method that's exposed on all Pages. 您可以使用所有页面上公开的protected virtual void LayoutChildren方法。 Keep in mind it may be called many times, so you'll need to account for that possibility. 请记住,它可能被多次调用,因此您需要考虑这种可能性。

Another option would be to simply add your child Views in the Page's constructor. 另一个选择是在页面的构造函数中简单地添加子视图。 This option is not ideal, but it's guaranteed to only be called once, and always before your Page is presented. 此选项不是理想的选择,但可以保证仅在显示页面之前调用一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM