Binding Enabled Property of Android Button Using MvvmCross

I have a problem when I try to associate the "Enabled" property of my Android button with the logical element of my ViewModel using the MvvmCross structure, and I really don't know its origin.

So, I have a ViewModel that contains the following two properties:

private ProjectDetailDTO _projectDetail; public ProjectDetailDTO ProjectDetail { get { return this._projectDetail; } set { _projectDetail = value; RaisePropertyChanged(() => ProjectDetail); RaisePropertyChanged(() => HasPicture); } } private bool _hasPicture; public bool HasPicture { get { return ((this.ProjectDetail != null) && !String.IsNullOrEmpty(this.ProjectDetail.Pictures)); } set { _hasPicture = value; RaisePropertyChanged(() => HasPicture); } } 

As you understand, my button is attached to the HasPicture property. Therefore, I have the following code for my button in my .axml file:

 <Button local:MvxLang="Text LblSeePicturesValue" local:MvxBind="Enabled HasPicture,Click ShowProjectPicturesCommand" android:id="@+id/buttonPictures" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> 

I do not think this is a ViewModel problem because my WP application works well with this code. In fact, my ProjectDetailDTO is populated with a web service call, therefore using an asynchronous method. I think that when the binding implementation is implemented, the HasPicture property has a false value. But with my ViewModel code, the HasPicture property should be updated when ProjectDetailDTO is populated. Is there something I did wrong in my Android view?

Thanks for any help!

+6
source share
1 answer

I think you see here some interaction between ICommand.CanExecute and the Enabled property. There is a discussion about this at https://github.com/MvvmCross/MvvmCross/issues/729

To get around this, try switching the binding to:

 local:MvxBind="Click ShowProjectPicturesCommand;Enabled HasPicture" 

(Also note that the separator in the bindings is ; - not a , )

+9
source

Source: https://habr.com/ru/post/971750/


All Articles