Ejemplo n.º 1
0
        public ContactsCell()
        {
            // Initalize all visual elements
            Container       = new Frame();
            ContainerLayout = new StackLayout();
            NameLabel       = new Label();
            SelectedImage   = new Image();

            // Setup all elements
            Container.WidthRequest          = 150;
            Container.HeightRequest         = 25;
            Container.Margin                = new Thickness(10, 0, 10, 10);
            Container.CornerRadius          = 25;
            Container.OutlineColor          = Color.Black;
            ContainerLayout.Orientation     = StackOrientation.Horizontal;
            NameLabel.VerticalOptions       = LayoutOptions.Center;
            SelectedImage.VerticalOptions   = LayoutOptions.Center;
            SelectedImage.HorizontalOptions = LayoutOptions.EndAndExpand;
            ContainerLayout.Children.Add(NameLabel);
            ContainerLayout.Children.Add(SelectedImage);
            Container.Content = ContainerLayout;

            ProfileContactNames     = SelectContactsPage.GetProfileContactNames();
            ProfileNumbersAsStrings = SelectContactsPage.GetProfileContactNumbers();
            ProfileNumbersAsLongs   = SelectContactsPage.GetProfileContactNumbersAsLongs();

            View = Container;
        }
Ejemplo n.º 2
0
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();
            Debug.WriteLine("ContactsCell: OnBindingContextChanged()");
            if (BindingContext != null)
            {
                NameLabel.Text = Name;

                if (PhoneNumbersAsStrings.Count == 0)
                {
                    Debug.WriteLine("Error: No phone numbers for this contact!");
                }
                if (PhoneNumberssAsLong.Count == 0)
                {
                    Debug.WriteLine("Error: No phone numbers as long for this contact!");
                }

                if (ProfileContactNames.Contains(Name))
                {
                    SelectedImage.Source = ImageSource.FromResource("Checked");
                }
                else if (!ProfileContactNames.Contains(Name))
                {
                    SelectedImage.Source = ImageSource.FromResource("NotChecked");
                }

                var imageTapGestureRecognizer = new TapGestureRecognizer();
                imageTapGestureRecognizer.Tapped += (sender, e) =>
                {
                    Debug.WriteLine("Selected Contact: " + Name);
                    if (ProfileContactNames.Contains(Name))
                    {
                        Debug.WriteLine("Contact is " + Name + " is now disselected ...");
                        SelectedImage.Source = ImageSource.FromResource("NotChecked");
                        SelectContactsPage.ModifyProfileContact('r', Name, PhoneNumbersAsStrings, PhoneNumberssAsLong);
                        foreach (string name in SelectContactsPage.GetProfileContactNames())
                        {
                            Debug.WriteLine(name);
                        }
                        foreach (string number in SelectContactsPage.GetProfileContactNumbers())
                        {
                            Debug.WriteLine(number);
                        }
                        foreach (long number in SelectContactsPage.GetProfileContactNumbersAsLongs())
                        {
                            Debug.WriteLine(number);
                        }
                    }
                    else if (!ProfileContactNames.Contains(Name))
                    {
                        Debug.WriteLine("Contact is " + Name + " is now selected ...");
                        SelectedImage.Source = ImageSource.FromResource("Checked");
                        SelectContactsPage.ModifyProfileContact('a', Name, PhoneNumbersAsStrings, PhoneNumberssAsLong);
                        foreach (string name in SelectContactsPage.GetProfileContactNames())
                        {
                            Debug.WriteLine(name);
                        }
                        foreach (string number in SelectContactsPage.GetProfileContactNumbers())
                        {
                            Debug.WriteLine(number);
                        }
                        foreach (long number in SelectContactsPage.GetProfileContactNumbersAsLongs())
                        {
                            Debug.WriteLine(number);
                        }
                    }
                };
                SelectedImage.GestureRecognizers.Add(imageTapGestureRecognizer);
            }
        }