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

  • Question

  • User317842 posted

    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.

    Sunday, May 24, 2020 10:54 AM

All replies

  • User369978 posted

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

        public Page1()
        {
            InitializeComponent();
    
            this.BindingContext = new BLEConncetViewModel(service, adapter);
        }
    
    Monday, May 25, 2020 9:00 AM
  • User397537 posted

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

    Thursday, April 15, 2021 2:05 PM