Xamarin表单显示阻止加载消息 [英] Xamarin Forms show blocking loading message
问题描述
我的任务很长时间,我想显示进度指示器和消息.
我尝试使用ActivityIndicator
,虽然它可以正确显示,但它允许更新基础控件.
此Xamarin
iOS
代码正是我想要的,但是我需要使用Xamarin.Forms
来完成.
http://developer.xamarin.com/recipes/ios/standard_controls/popovers/display_a_loading_message/
有什么想法吗?
创建一个自定义渲染器,该渲染器将 BoxView 覆盖在整个屏幕上.您可以根据自己的喜好自定义颜色填充和不透明度以显示基本内容.
然后,您可以在屏幕中间居中放置 Xamarin.Forms ActivityIndicator ,以结束相同的效果.
注意-但是,当前在 v1.2.3x 中, Android 中存在一个错误,该错误使基础控件仍可以接收用户输入事件,就像单击按钮一样,尽管 BoxView 位于所有内容的顶部.
显然,此问题已在即将发布的 v1.3 版本中解决.
更新1
作为复杂控件的一部分,它不容易提取,但是要获得与链接中类似的效果并不难.
在页面中尝试以下操作:-
使用网格作为基础( 1行1列),并将其设置为填充屏幕,并将行和列定义设置为 GridUnitType.Star .
然后,您可以像普通的那样,作为网格的子创建页面内容,将此放置在单元格(0,0)上./p>
对于下一部分(您可以将其放在控件渲染器中),以便可以轻松地在多个页面上重复使用它.如果您对控制渲染器不太满意,则始终可以创建一个函数来返回 Grid 对象,但是您可以在多个页面上使用它:-
-
网格作为基础
-
BoxView 作为网格
的子级
-
ActivityIndicator 作为网格的子级.
-
一旦获得上述的 Grid 结果,您也可以将其添加到页面的 Grid 根控件中,然后重新放置- 在单元格(0,0).
然后,您可以控制此覆盖面板在您的内容上的可见性.
自然,每当您显示/隐藏面板时,您都希望设置 ActivityIndicator 的 IsRunning 属性. .只需创建几个方法,例如 ShowActivityIndicator()和 HideActivityIndicator()即可简化此过程.
I have a long running task and I want to show a progress indicator and message.
I have tried using the ActivityIndicator
and while it shows correctly, it allows the underlying controls to be updated.
This Xamarin
iOS
code is just what I want but I need to do it in using Xamarin.Forms
.
http://developer.xamarin.com/recipes/ios/standard_controls/popovers/display_a_loading_message/
Any ideas?
Create a custom renderer that overlays a BoxView over the entire screen. You can customize the color fill and the opacity to show underlying contents to your liking.
You can then center a Xamarin.Forms ActivityIndicator in the middle of the screen to finish off the same effect.
Note - however, currently in v1.2.3x there is a bug on Android that allows underlying controls to still receive user input events, like a button click, despite the BoxView being on-top of everything.
This issues is apparently resolved in the upcoming v1.3 release.
Update 1
Its not easily extractable as its part of a more complex control, however it isn't that difficult to get a similar effect to that in your link.
Try the following in your page:-
Use a Grid as the base (1 row, 1 column), and set it to fill the screen, and set the row and column definitions to GridUnitType.Star.
You can then create your page content like normal as a child of Grid, position this at cell (0,0).
For the next part (you could put this in a control renderer) so that it could be re-used easily across multiple pages. If your not that comfortable with control renderers, you can always create a function to return a Grid object however that you can use across multiple pages:-
Grid as your base
BoxView as a child of the Grid
ActivityIndicator as a child of the Grid.
Once you have the Grid result from the above, you can add this also to your page's Grid root control, position this again - at cell (0,0).
You can then control the visibility of this overlaying panel on your content.
Naturally you will want to set the IsRunning property of the ActivityIndicator whenever you show / hide the panel. Just create a couple methods like ShowActivityIndicator(), and HideActivityIndicator() perhaps to simplify this though.
这篇关于Xamarin表单显示阻止加载消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!