gpt4 book ai didi

xamarin - 如何在屏幕中间显示 ActivityIndi​​cator?

转载 作者:行者123 更新时间:2023-12-02 06:53:47 25 4
gpt4 key购买 nike

我创建了一个事件指示器并将其添加到 StackLayout,当我让它运行时,它在模拟器中显示在右上角 Android 4.4,在 iOS 中不显示,在 Android 6 手机中不显示.

var indicator = new ActivityIndicator()
{
Color = Color.Blue,
};
indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy", BindingMode.OneWay);
indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy", BindingMode.OneWay);
AbsoluteLayout.SetLayoutFlags(indicator, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
mainLayout.Children.Add(indicator);

我想将事件指示器显示在屏幕中央,因为该操作需要时间才能完成。

最佳答案

您在状态栏中看到的指示器是基页类的 IsBusy 属性的默认行为。您的代码不起作用的原因是因为您试图将 ActivityIndi​​cator 的可见性绑定(bind)到该属性 - 但您没有指定绑定(bind)源。如果您查看调试器的应用程序输出日志,那么您可能会看到类似“在类型‘Object’上找不到属性‘IsBusy’”的消息。

要修复它,您只需将每个绑定(bind)的绑定(bind)上下文指向表单。试一试:

public partial class App : Application
{
public App ()
{
var mainLayout = new AbsoluteLayout ();
MainPage = new ContentPage {
Content = mainLayout
};

var containerPage = Application.Current.MainPage;

var indicator = new ActivityIndicator() {
Color = Color.Blue,
};
indicator.SetBinding(VisualElement.IsVisibleProperty, new Binding("IsBusy", BindingMode.OneWay, source: containerPage));
indicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding("IsBusy", BindingMode.OneWay, source: containerPage));
AbsoluteLayout.SetLayoutFlags(indicator, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
mainLayout.Children.Add(indicator);

containerPage.IsBusy = true;
}
}

关于xamarin - 如何在屏幕中间显示 ActivityIndi​​cator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36177128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com