Forum Xamarin.Android

Binding:Property not found

This is my project
-Mainpage.xaml:

   <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                xmlns:local="clr-namespace:XamarinClient"
                x:Class="XamarinClient.MainPage"
                Title="OPC UA Client">
       <ContentPage.BindingContext>
           <local:ConnectionListViewModel/>
       </ContentPage.BindingContext>
       <ContentPage.Content>
           <StackLayout  Margin = "20,20,20,20">
               <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="Fill">
                   <Label Text="OPC UA server's endpoint URL:" FontSize="Medium" TextColor="#0066ff" FontAttributes="Bold"/>                       
                   <Entry x:Name="EntryUrl" Placeholder="Write your EndpointUrl here" Text="{Binding ConnectionName}"/>
                <ListView x:Name="ContactsList" ItemsSource="{Binding Connections}" > 

-ConnectionListViewModel:

  namespace XamarinClient
  {
        public class ConnectionListViewModel:INotifyPropertyChanged
   {
       public ICommand AddConnectionNameCommand => new Command (AddConnectionName);
      public ObservableCollection<string> Connections { get; set; }
      public string ConnectionName { get; set; }
      public string ConnectionUrl { get; set; }
      public ConnectionListViewModel()
      {
              Connections = new ObservableCollection<string>();
              Connections.Add("text");
      }
      public void  AddConnectionName()
      {
              Connections.Add(ConnectionName);
      }
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyChanged(string propertyName)
      {
              if (this.PropertyChanged != null)
                  this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
      }
  }

When run this Project the output of Debug:

[0:] Binding: 'ConnectionName' property not found on 'XamarinClient.ConnectionListViewModel', target property: 'Xamarin.Forms.Entry.Text'

Binding to the Listview "Connections" is OK but Binding to Entry"ConnectionName" it not working. How to fix this?Thanks <3

Best Answer

  • jezhjezh Xamurai
    Accepted Answer

    I attach my project below

    Hi,freind, I couldn't see your project.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    I tested your code , but I couldn't reproduce this question.It works properly.
    I init the data in the constructor like this:

        public ConnectionListViewModel()
            {
                Connections = new ObservableCollection<string>();
                Connections.Add("text");
                Connections.Add("text2");
                Connections.Add("text3");
    
                ConnectionName = "test123";
            }
    

    ConnectionListViewModel.cs

     public class ConnectionListViewModel: INotifyPropertyChanged
        {
            public ICommand AddConnectionNameCommand => new Command(AddConnectionName);
            public ObservableCollection<string> Connections { get; set; }
            public string ConnectionName { get; set; }
    
    
            public string ConnectionUrl { get; set; }
            public ConnectionListViewModel()
            {
                Connections = new ObservableCollection<string>();
                Connections.Add("text");
                Connections.Add("text2");
                Connections.Add("text3");
    
                ConnectionName = "test123";
            }
            public void AddConnectionName()
            {
                Connections.Add(ConnectionName);
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
            private void OnPropertyChanged(string propertyName)
            {
                if (this.PropertyChanged != null)
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    

    The result is

    You can check the test demo here.

  • NhatTran98NhatTran98 Member

    Its not working in my project. I attach my project below. UA xamarin Client. Can you check it for me? Thank you

    [0:] Binding: 'ConnectionName' property not found on 'XamarinClient.ConnectionListViewModel', target property: 'Xamarin.Forms.Entry.Text'

  • jezhjezh Member, Xamarin Team Xamurai
    Accepted Answer

    I attach my project below

    Hi,freind, I couldn't see your project.

Sign In or Register to comment.