Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

c# - Problems with mvvmcross Binding on IOS (Works on Simulator, but some properties doesn't work on the Device)

The problem consists on the binding to a UIBarButtonItem, the code works on Simulator, but on the device the property Enable doesn't work and the Clicked Works…

The same problem exists in the textViewItem, but this time neither the text or enable works.

    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);
        }
    }
(...)
 }

Thanks in advance

[EDIT]

The Application Output: 2013-01-11 09:16:56.369 LinkFENACAMSIGEPMobileUIIPad[6496:c07] Navigation: Diagnostic: 2.24 Navigate to MainMenuViewModel with args

2013-01-11 09:16:56.369 LinkFENACAMSIGEPMobileUIIPad[6496:c07] TouchNavigation: Diagnostic: 2.24 Navigate requested

2013-01-11 09:16:56.421 LinkFENACAMSIGEPMobileUIIPad[6496:c07] MvxBind: Warning: 2.29 Unable to bind to source is null

2013-01-11 09:16:56.423 LinkFENACAMSIGEPMobileUIIPad[6496:c07] MvxBind: Warning: 2.29 Unable to bind to source is null

[EDIT 20130111:11:12] - Linker Behavior: Link SDK assemblies only

Similiar To: MvvmCross Monotouch - Fail to bind Properties on a real iPad, but it works on the Simulator (I Can't make this work...)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can't see the barbutton in the example code included - so I'll answer based on the Text, Clicked, Enabled, etc.

If this is working in Simulator, but not on the device, the chances are this is to do with the Linker - exactly like in MvvmCross Monotouch - Fail to bind Properties on a real iPad, but it works on the Simulator

To test this theory, try turning the linker to include all symbols


Assuming this is the cause of the problem... then to workaround it you need to include a LinkerPleaseInclude.cs file which will trick the Linker into including these properties.

For example it might just look like:

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";
    }
}

Note: that this code is never actually executed, but is analysed by the Linker at build time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...