Xamarin.ios MvvmCross绑定到MvxDialogViewController中的进度指示器

Xamarin.ios MvvmCross绑定到MvxDialogViewController中的进度指示器,xamarin.ios,mvvmcross,Xamarin.ios,Mvvmcross,我有一个MvxDialogViewController,我试图通过添加可绑定属性来使用Xamarin示例中显示的进度指示器 当我以编程方式将Visble设置为true时,我可以让指示器出现,但当我绑定到vm属性时,它不会出现 以下是查看代码: var bindings = this.CreateInlineBindingTarget<LoginViewModel>(); Root = new RootElement("Login") { new Section("Login

我有一个MvxDialogViewController,我试图通过添加可绑定属性来使用Xamarin示例中显示的进度指示器

当我以编程方式将Visble设置为true时,我可以让指示器出现,但当我绑定到vm属性时,它不会出现

以下是查看代码:

var bindings = this.CreateInlineBindingTarget<LoginViewModel>();

Root = new RootElement("Login")
{
    new Section("Login Credentials")
    {
        new EntryElement("Username", "Enter user name").Bind(bindings, vm => vm.UserName),
        new EntryElement("Password", "Enter password", "", true).Bind(bindings, vm => vm.Password)
    }
};

_bindableProgress = new BindableProgress(UIScreen.MainScreen.Bounds).Bind(bindings, b => b.Visible, vm => vm.IsBusy);
_bindableProgress.Title = "Logging in...";
View.Add(_bindableProgress);

它在安卓系统中运行良好,所以我猜问题不在于此。

IsBusy
在绑定时可能是错误的。因此,
\u visible
设置为
false
,并调用
Hide()
。现在该视图已从superview中删除,您无法再显示它,因为
show()
不会再次将其添加到superview中。尝试省略
RemoveFromSuperview()。或者修改
可见的
属性,如下所示:

var set = this.CreateBindingSet<LoginView, LoginViewModel>();
set.Bind(_bindableProgress).For(b => b.Title).To(vm => vm.ProgressTitle);
set.Bind(_bindableProgress).For(b => b.Visible).To(vm => vm.IsBusy);
set.Apply();
public bool可见
{
获取{return\u visible;}
设置
{
如果(_visible==值)
回来
_可见=价值;
如果(_可见)
{
Show();
}
其他的
{
隐藏();
}
}
}

您的虚拟机属性是什么样子的?设置忙属性时是否正在调用RaisePropertyChanged?调试跟踪中有什么奇怪的东西吗?我已经更新了这个问题,将vm属性包括在内。我敢肯定问题不在于这个。我将查看调试跟踪。听起来很有希望。我会在星期二回去工作的时候试试。我做了改变,但仍然不起作用。我现在可以使用它了,但我必须创建一个包装器类,绑定到该类,并从中设置可见。出于某种原因,MvvmCross不希望绑定到BindableProgress类-也许您无法从另一个视图绑定到一个视图。
public class BindableProgress : UIView
{
    private UIActivityIndicatorView _activitySpinner;
    private UILabel _loadingLabel;

    public string Title { get; set; }

    private bool _visible;
    public bool Visible
    {
        get { return _visible; }
        set
        {
            _visible = value;
            if (_visible)
            {
                Show();
            }
            else
            {
                Hide();
            }
        }
    }

    public BindableProgress(RectangleF frame) : base(frame)
    {
        // configurable bits
        BackgroundColor = UIColor.Black;
        Alpha = 0;
        AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;

        float labelHeight = 22;
        float labelWidth = Frame.Width - 20;

        // derive the center x and y
        float centerX = Frame.Width/2;
        float centerY = Frame.Height/2;

        // create the activity spinner, center it horizontally and put it 5 points above center x
        _activitySpinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
        _activitySpinner.Frame = new RectangleF(
            centerX - (_activitySpinner.Frame.Width / 2),
            centerY - _activitySpinner.Frame.Height - 20,
            _activitySpinner.Frame.Width,
            _activitySpinner.Frame.Height);
        _activitySpinner.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
        AddSubview(_activitySpinner);


        // create and configure the label
        _loadingLabel = new UILabel(new RectangleF(
            centerX - (labelWidth/2),
            centerY + 20,
            labelWidth,
            labelHeight
            ));
        _loadingLabel.BackgroundColor = UIColor.Clear;
        _loadingLabel.TextColor = UIColor.White;
        _loadingLabel.TextAlignment = UITextAlignment.Center;
        _loadingLabel.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
        AddSubview(_loadingLabel);
    }

    private void Show()
    {
        _loadingLabel.Text = Title;
        Alpha = 0.75f;
        _activitySpinner.StartAnimating();
    }


    /// <summary>
    /// Fades out the control and then removes it from the super view
    /// </summary>
    private void Hide()
    {
        _activitySpinner.StopAnimating();

        Animate(
            0.5, // duration
            () => { Alpha = 0; },
            () => { RemoveFromSuperview(); }
            );
    }
}
private bool _isBusy;
public bool IsBusy
{
    get { return _isBusy; }
    set { _isBusy = value; RaisePropertyChanged(() => IsBusy); }
}