Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Picker Binding problem

$
0
0

I have a picker Binding problem from view to ViewModel
myview

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="AttendanceSystem.AbsenteesPage">
    <ContentPage.Content>
        <StackLayout>
            <Picker ItemsSource="{Binding Department}"  SelectedItem="{Binding SelectedDepartment}"></Picker>
        </StackLayout>

    </ContentPage.Content>
</ContentPage>

my view.cs

public AbsenteesPage()
    {
        InitializeComponent();
        BindingContext = new AbsenteesViewModel();
    }

myViewModel

public  class AbsenteesViewModel : BaseViewModel
{
    public  AbsenteesViewModel()
    {

    }
List<string> Department = new List<string>()
    {
        "Department of Computer Science and Engineering",
        "Department of Electronics and Communication Engineering",
        "Department of Electrical and Electronics Engineering",
        "Department of Information Technology",
        "Department of Civil Engineering",
        "Department of Mechanical Engineering",
        "Department of BioTechnology"
    };
    private string _selectedDepartment = "Department of Computer Science and Engineering";
    public string SelectedDepartment
    {
        get { return _selectedDepartment; }
        set
        {

            _selectedDepartment = value;
                OnPropertyChanged();

        }
    }
}

baseviewModel

public class BaseViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    }
       public BaseViewModel()
       {

       }
}


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>