Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Can any one please can help me with my problem with BindingContext?

GentiGaceGentiGace USMember ✭✭
edited May 2020 in Xamarin.Forms

Hi, everyone I need help for my problem. I am trying to bind the context from the viewmodel like this

<ContentPage.BindingContext> <viewModels:BLEConncetViewModel/> </ContentPage.BindingContext>

and also I have a constructor inside my view model that it have some parameters on it, here its starts the problem because when I try to bind it appears this message Type 'Type BLEConnectViewModel' is not usable as an object element because is not public or does not define a public parameterless constructor or a type converter. No default constructor found.

And the constructor is like this: I am using Prism container.

public BLEConncetViewModel(INavigationService navigationService, IAdapter btAdapter)
{
_navigationService = navigationService;
_btAdapter = btAdapter;
_btAdapter.DeviceDiscovered += OnDeviceDiscovered;
OnClickCommand = new DelegateCommand(OnClick);

    }

Thanks.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Instantiate the model in code behind , pass the parameter into it .

        public Page1()
        {
            InitializeComponent();
    
            this.BindingContext = new BLEConncetViewModel(service, adapter);
        }
    
  • GaelmartGaelmart Member ✭✭

    Where do you then get the service, adapter from in the code behind.

Sign In or Register to comment.