c# - IOS 上的 mvvmcross 绑定(bind)问题(在模拟器上工作,但某些属性在设备上不起作用)

标签 c# xamarin.ios mvvmcross

问题在于绑定(bind)到 UIBarButtonItem,代码在模拟器上工作,但在设备上,属性 Enable 不起作用,并且 Clicked Works…

textViewItem 中也存在同样的问题,但这次 text 或 enable 都不起作用。

    public partial class ProcessDetailViewController : MvxBindingTouchViewController<ProcessDetailViewModel>
{
    public ProcessDetailViewController (MvxShowViewModelRequest request)
        : base (request,"ProcessDetailViewController", null)
    {
    }

    public override void DidReceiveMemoryWarning ()
    {
        // Releases the view if it doesn't have a superview.
        base.DidReceiveMemoryWarning ();

        // Release any cached data, images, etc that aren't in use.
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        this.AddBindings(
            new Dictionary<object, string>()
            {
            { this.lblSeguradoraNome , "{'Text':{'Path':'AssuranceCompanyID'}}" },
            { this.lblSeguradoraGestor , "{'Text':{'Path':'AssuranceManager'}}" },
            { this.lblApoliceData , "{'Text':{'Path':'InsurancePolicyStartDate'}}" },
            { this.lblApoliceNum , "{'Text':{'Path':'InsurancePolicyNumber'}}" },
            { this.lblApoliceRamo , "{'Text':{'Path':'InsurancePolicyBranch'}}" },
            { this.lblDataPedido , "{'Text':{'Path':'RequestDate'}}" },
            { this.lblGestor , "{'Text':{'Path':'InternalManager'}}" },
            { this.lblLocalRiscoCodPostal , "{'Text':{'Path':'InsurancedLocationAddressCityZipCode'}}" },
            { this.lblLocalRiscoConcelho , "{'Text':{'Path':'InsurancedLocationAddressCity'}}" },
            { this.lblLocalRiscoMorada , "{'Text':{'Path':'InsurancedLocationAddress'}}" },
            { this.lblPerito , "{'Text':{'Path':'Surveyer'}}" },
            { this.lblSeguradoCodPostal , "{'Text':{'Path':'InsuredPersonAddressCityZipCode'}}" },
            { this.lblSeguradoConcelho , "{'Text':{'Path':'InsuredPersonAddressCity'}}" },
            { this.lblSeguradoContacto , "{'Text':{'Path':'InsuredPersonPhone'}}" },
            { this.lblSeguradoMorada , "{'Text':{'Path':'InsuredPersonAddress'}}" },
            { this.lblSeguradoNome , "{'Text':{'Path':'InsuredPersonName'}}" },
            { this.btnDownload , "{'Clicked':{'Path':'DownloadProcessButton'},'Enabled':{'Path':'HideIfDownloaded'}}" },
            { this.btnTerminarVisita , "{'Clicked':{'Path':'EndVisitButton'},'Enabled':{'Path':'ShowIfOnVisit'}}" },
            { this.btnObterLocalizacao , "{'Clicked':{'Path':'AdquireLocationButton'},'Enabled':{'Path':'ShowIfOnVisit'}}" },
            { this.btnIniciarVisita , "{'Clicked':{'Path':'BeginVisitButton'},'Enabled':{'Path':'HideIfOnVisit'}}" },
            { this.btnTirarFoto , "{'Clicked':{'Path':'TakePhotoButton'},'Enabled':{'Path':'ShowIfOnVisit'}}" },
            { this.btnVoltar , "{'Clicked':{'Path':'ReturnButton'}}" },
            { this.btnUpload , "{'Clicked':{'Path':'UploadProcessButton'},'Enabled':{'Path':'CanUpload'}}" },
            }
        );
    //  var a= NavigationItem.LeftBarButtonItems[0].Enabled

        // Perform any additional setup after loading the view, typically from a nib.
    }

    public override void ViewDidUnload ()
    {
        base.ViewDidUnload ();

        // Clear any references to subviews of the main view in order to
        // allow the Garbage Collector to collect them sooner.
        //
        // e.g. myOutlet.Dispose (); myOutlet = null;

        ReleaseDesignerOutlets ();
    }

    public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
    {
        // Return true for supported orientations
        return true;
    }
 }

 public class ProcessDetailViewModel : ProcessNavigationBaseViewModel
{(...)}

public class ProcessNavigationBaseViewModel : BaseViewModel
{
    (...)

    #region Properties
    private Process _currentProcess;

    private static User _user;

    private bool _isGPSLocationStarted;

    private double _latitude;

    private double _longitude;

    private string _photoFilename = "";

    public Process CurrentProcess
    {
        get
        {
            return _currentProcess;
        }
        set
        {
            _currentProcess = value;
            FirePropertyChanged(() => CurrentProcess);
        }
    }

    public User User
    {
        get { return _user; }
        set
        {
            _user = value;
            FirePropertyChanged(() => User);
        }
    }

    private bool _isDownloaded
    {
        get
        {
            return CurrentProcess.IsLockedInServer && !(CurrentProcess.ProcessState == ProcessState.WaitingReportProduction.ToString());
        }
        set
        {
            CurrentProcess.IsLockedInServer = value;
            FirePropertyChanged(() => ShowIfDownloaded);
            FirePropertyChanged(() => HideIfDownloaded);
        }
    }

    public bool ShowIfDownloaded
    {
        get { return _isDownloaded; }
    }

    public bool HideIfDownloaded
    {
        get { return !_isDownloaded; }
    }

    public bool CanUpload
    {
        get { return ( CurrentProcess.ProcessState == ProcessState.WaitingUpload.ToString()); }
    }

    public bool CanDownload
    {
        get { return (CurrentProcess.ProcessState != ProcessState.WaitingReportProduction.ToString() && 
                                    CurrentProcess.ProcessState == ProcessState.WaitingSurveyorAcceptionDecision.ToString()) ;  }
    }

    public bool ShowIfOnVisit
    {
        get { return (CurrentProcess.ProcessState == ProcessState.OnVisist.ToString()); }
    }

    public bool HideIfOnVisit
    {
        get { return (!(CurrentProcess.ProcessState == ProcessState.OnVisist.ToString())) && ShowIfDownloaded; }
    }

    public string ProcessDescription
    {
        get
        {
            return string.Format("{0} - {1}", CurrentProcess.ProcessNumber, CurrentProcess.RequestedService.RequestedServiceType);
        }
    }
(...)
 }

提前致谢

[编辑]

应用输出: 2013-01-11 09:16:56.369 LinkFENACAMSIGEPMobileUIIPad[6496:c07] 导航:诊断:2.24 使用参数导航到 MainMenuViewModel

2013-01-11 09:16:56.369 LinkFENACAMSIGEPMobileUIIPad[6496:c07] TouchNavigation:诊断:2.24 请求导航

2013-01-11 09:16:56.421 LinkFENACAMSIGEPMobileUIIPad[6496:c07] MvxBind:警告:2.29 无法绑定(bind)到源为空

2013-01-11 09:16:56.423 LinkFENACAMSIGEPMobileUIIPad[6496:c07] MvxBind:警告:2.29 无法绑定(bind)到源为空

[编辑 20130111:11:12] - 链接器行为:仅链接 SDK 程序集

类似于: MvvmCross Monotouch - Fail to bind Properties on a real iPad, but it works on the Simulator (我无法完成这项工作...)

最佳答案

我在包含的示例代码中看不到栏按钮 - 所以我将根据文本、单击、启用等进行回答。

如果这在模拟器中有效,但在设备上无效,这很可能与链接器有关 - 与 MvvmCross Monotouch - Fail to bind Properties on a real iPad, but it works on the Simulator 中的完全一样

为了检验这个理论,尝试将链接器设置为包含所有符号


假设这是问题的原因...那么要解决它,您需要包含一个 LinkerPleaseInclude.cs 文件,该文件将诱使链接器包含这些属性。

例如它可能看起来像:

public class LinkerIncludePlease
{
    private void IncludeClicked(UIButton button)
    {
        button.Clicked += (s, e) => { };
    }

    private void IncludeEnabled(UIButton button)
    {
        button.Enabled = !button.Enabled;
    }

    private void IncludeText(UILabel label)
    {
        label.Text = label.Text + "test";
    }
}

注意:此代码从未实际执行,而是在构建时由链接器分析。

关于c# - IOS 上的 mvvmcross 绑定(bind)问题(在模拟器上工作,但某些属性在设备上不起作用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14275499/

相关文章:

c# - 上下文菜单条 -> 更改突出显示项目的颜色

c# - 在 pcl 中使用 TcpClient 以针对 ios 和 android 的 xamarin

c# - DidReceiveRemoteNotification 未在后台调用 - Xamarin iOS - 推送通知

c# - 从 View 模型导航到mvvmcross中的另一个 View 模型时崩溃

c# - ViewModel 中未调用方法 - MVVMCross

C# DataGridView.Rows.ToString() 方法

c# - 使用 Unity 创建一个实例并在任何地方使用它

c# - 捕获 XamlParseException 中丢失的 DLL

ios - 将 Xamarin Forms 中的编辑器滚动到 View 中

windows-phone-8 - 通用应用程序(WP&WinRT)我应该使用Cirrious MvvmCross还是Galasoft MVVM Light Toolkit