Example #1
0
 public Xamarin.Forms.SearchBar AddSearchBar(Layout <View> view, int row = 0)
 {
     this.FormSearchBar = new Xamarin.Forms.SearchBar {
         Placeholder = "Filter...", HeightRequest = 24, BackgroundColor = Color.DimGray, TextColor = Color.Black, PlaceholderColor = Color.DarkGray
     };
     this.FormSearchBar.TextChanged += SearchBarTextChanged;
     Grid.SetRow(this.FormSearchBar, row);
     view.Children.Add(this.FormSearchBar);
     return(this.FormSearchBar);
 }
        internal static bool HasDefaultFont(this Xamarin.Forms.SearchBar element)
        {
            if (element.FontFamily != null || element.FontAttributes != FontAttributes.None)
            {
                return(false);
            }

            var getNamedSize = typeof(Device).GetRuntimeMethod("GetNamedSize", new Type[] { typeof(NamedSize), typeof(Type), typeof(bool) });

            if (getNamedSize != null)
            {
                var result = (double)getNamedSize.Invoke(null, new object[] { NamedSize.Default, typeof(Label), true });
                return(result == element.FontSize);
            }
            return(false);
        }
Example #3
0
        public iOSSearchBarPageCS()
        {
            Xamarin.Forms.SearchBar searchBar = new Xamarin.Forms.SearchBar {
                Placeholder = "Enter search term"
            };
            searchBar.On <iOS>().SetSearchBarStyle(UISearchBarStyle.Minimal);

            Button styleButton = new Button {
                Text = "Toggle SearchBar Style"
            };

            styleButton.Clicked += (s, e) =>
            {
                switch (searchBar.On <iOS>().GetSearchBarStyle())
                {
                case UISearchBarStyle.Default:
                    searchBar.On <iOS>().SetSearchBarStyle(UISearchBarStyle.Minimal);
                    break;

                case UISearchBarStyle.Minimal:
                    searchBar.On <iOS>().SetSearchBarStyle(UISearchBarStyle.Prominent);
                    break;

                case UISearchBarStyle.Prominent:
                    searchBar.On <iOS>().SetSearchBarStyle(UISearchBarStyle.Default);
                    break;
                }
            };

            Button backgroundButton = new Button {
                Text = "Toggle Background"
            };

            backgroundButton.Clicked += (s, e) => searchBar.BackgroundColor = (searchBar.BackgroundColor == Color.Teal) ? Color.Default : Color.Teal;

            Title   = "SearchBar Style";
            Content = new StackLayout
            {
                Children =
                {
                    searchBar,
                    styleButton,
                    backgroundButton
                }
            };
        }
Example #4
0
        public WindowsSearchBarPageCS()
        {
            var searchBar = new Xamarin.Forms.SearchBar {
                Text = "Enter search term here"
            };

            searchBar.On <Windows>().SetIsSpellCheckEnabled(true);

            var toggleButton = new Button {
                Text = "Toggle spell check"
            };

            toggleButton.Clicked += (sender, e) =>
            {
                searchBar.On <Windows>().SetIsSpellCheckEnabled(!searchBar.On <Windows>().GetIsSpellCheckEnabled());
            };

            Title   = "SearchBar Spell Check";
            Content = new StackLayout
            {
                Margin   = new Thickness(20),
                Children = { searchBar, toggleButton }
            };
        }
 protected override void OnDetachingFrom(Xamarin.Forms.SearchBar bindable)
 {
     base.OnDetachingFrom(bindable);
     bindable.TextChanged -= Bindable_TextChanged;
 }
 protected override void OnAttachedTo(Xamarin.Forms.SearchBar bindable)
 {
     base.OnAttachedTo(bindable);
     bindable.TextChanged += Bindable_TextChanged;
 }
Example #7
0
        public MenuPage()
        {         

            var searchBar = new Xamarin.Forms.SearchBar();
            searchBar.TextChanged += (sender, e) =>
            {                
                //search                                 
            };

            Icon = UtilityResources.icon_Test;
            Title = "menu"; // The Title property must be set.
            BackgroundColor = Color.FromHex("FFFFFF");
            Menu = new ListView
            {
                RowHeight = 80,
                Footer = new BoxView { BackgroundColor = Color.Transparent, HeightRequest = 95, MinimumHeightRequest = 95 },
                ItemTemplate = new DataTemplate(() =>
                {
                    Color textColor = Color.Black;

                    Label nameLabel = new Label();
                    nameLabel.TextColor = textColor;
                    nameLabel.SetBinding(Label.TextProperty, "Description");                    

                    var disclosure = new Image()
                    {
                        BackgroundColor = Color.Transparent,
                        Aspect = Aspect.AspectFit,
                        Source = UtilityResources.freccia_dx
                    };

                    int dimPpoint = 30;
                    int dimDisclosure = 12;

                    RelativeLayout cell = new RelativeLayout();
                    cell.Children.Add(nameLabel,
                            Constraint.RelativeToParent((parent) =>
                            {
                                return dimPpoint;
                            }),
                            Constraint.RelativeToParent((parent) =>
                            {
                                return parent.Height / 3;
                            }),
                            Constraint.RelativeToParent((parent) =>
                            {
                                return parent.Width - dimPpoint - 20;
                            }),
                            Constraint.RelativeToParent((parent) =>
                            {
                                return parent.Height / 3;
                            })
                        );                                      

                    cell.Children.Add(disclosure,
                            Constraint.RelativeToParent((parent) =>
                            {
                                return parent.Width - 20;
                            }),
                            Constraint.RelativeToParent((parent) =>
                            {
                                return (parent.Height - 20) / 2;
                            }),
                            Constraint.RelativeToParent((parent) =>
                            {
                                return dimDisclosure;
                            }),
                            Constraint.RelativeToParent((parent) =>
                            {
                                return 20;
                            })
                        );

                    return new ViewCell
                    {
                        View = cell

                    };
                })
            };

            var backLabel = new BoxView
            {
                BackgroundColor = Color.FromHex("EDEBE6")
            };

            //Titolo
            var menuLabel = new ContentView
            {
                Padding = new Thickness(0, 0, 0, 0),
                Content = new Label
                {
                    TextColor = Color.FromHex("005DAB"),
                    Text = "Globo",
                    FontSize = 21,
                    BackgroundColor = Color.Transparent,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions = LayoutOptions.End
                }
            };


            #region AGGIONRAMENTO
            RelativeLayout rlAggiornamento = new RelativeLayout();

            var imgAgg = new Image()
            {
                BackgroundColor = Color.Transparent,
                Aspect = Aspect.AspectFit,
                Source = UtilityResources.icon_Test
            };

            var nameLabelAgg = new Label()
            {
                FontSize = 15,
                TextColor = Color.Black, //Color.FromHex ("005DAB"),
                BackgroundColor = Color.Transparent,
                Text = UtilityStringResources.nameLabelAgg,
                VerticalTextAlignment = TextAlignment.Center
            };

            var lineAgg = new BoxView()
            {
                BackgroundColor = Color.Gray
            };

            var btnAggiornamento = new Button()
            {
                BackgroundColor = Color.Transparent
            };
            btnAggiornamento.Clicked += BtnUpdate_Clicked;

            rlAggiornamento.Children.Add(imgAgg,
                Constraint.RelativeToParent((parent) => {
                    return parent.Height / 4;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Height / 4;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Width / 6;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Height / 2;
                })
            );
            rlAggiornamento.Children.Add(nameLabelAgg,
                Constraint.RelativeToParent((parent) => {
                    return parent.Width / 6 + 20;
                }),
                Constraint.RelativeToParent((parent) => {
                    return 0;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Width;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Height;
                })
            );
            rlAggiornamento.Children.Add(lineAgg,
                Constraint.RelativeToParent((parent) => {
                    return parent.Height / 4;
                }),
                Constraint.RelativeToParent((parent) => {
                    return 0;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Width;
                }),
                Constraint.RelativeToParent((parent) => {
                    return 0.5;
                })
            );

            rlAggiornamento.Children.Add(btnAggiornamento,
                Constraint.RelativeToParent((parent) => {
                    return 0;
                }),
                Constraint.RelativeToParent((parent) => {
                    return 0;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Width;
                }),
                Constraint.RelativeToParent((parent) => {
                    return parent.Height;
                })
            );

            var aggiornamentoLabel = new ContentView
            {
                Padding = new Thickness(0, 0, 0, 0),
                Content = rlAggiornamento
            };
            #endregion

            StackLayout st = new StackLayout();
            st.Children.Add(searchBar);
            st.Children.Add(Menu);

            RelativeLayout rLmenu = new RelativeLayout();

            float wTestata = 375;
            float hTestata = 64;
            float pTestata = (App.ScreenWidth * hTestata) / wTestata;

            if(Device.Idiom == TargetIdiom.Phone)
            {              

                rLmenu.Children.Add(backLabel,
                    Constraint.RelativeToParent((parent) => {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return parent.Width;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return pTestata;
                    })
                );
                rLmenu.Children.Add(menuLabel,
                    Constraint.RelativeToParent((parent) => {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return parent.Width;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return pTestata - 5;
                    })
                );

                rLmenu.Children.Add(st,
                    Constraint.RelativeToParent((parent) => {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return hTestata;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return parent.Width;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return parent.Height - pTestata - 100;
                    })
                );

                rLmenu.Children.Add(aggiornamentoLabel,
                    Constraint.RelativeToParent((parent) => {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return parent.Height - 50;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return parent.Width;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return 50;
                    })
                );
            }
            else
            {
                rLmenu.Children.Add(backLabel,
                  Constraint.RelativeToParent((parent) => {
                      return 0;
                  }),
                  Constraint.RelativeToParent((parent) => {
                      return 0;
                  }),
                  Constraint.RelativeToParent((parent) => {
                      return parent.Width;
                  }),
                  Constraint.RelativeToParent((parent) => {
                      return parent.Height * 10 / 100;
                  })
               );

                rLmenu.Children.Add(menuLabel,
                    Constraint.RelativeToParent((parent) => {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return 15;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return parent.Width;
                    }),
                    Constraint.RelativeToParent((parent) => {
                        return backLabel.Height - 15;
                    })
                );

                rLmenu.Children.Add(st,
                    Constraint.RelativeToParent((parent) =>
                    {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) =>
                    {
                        return backLabel.Height + 20;
                    }),
                    Constraint.RelativeToParent((parent) =>
                    {
                        return parent.Width;
                    }),
                    Constraint.RelativeToParent((parent) =>
                    {
                        return parent.Height - 100;
                    })
                );

                rLmenu.Children.Add(aggiornamentoLabel,
                    Constraint.RelativeToParent((parent) =>
                    {
                        return 0;
                    }),
                    Constraint.RelativeToParent((parent) =>
                    {
                        return parent.Height - 50;
                    }),
                    Constraint.RelativeToParent((parent) =>
                    {
                        return parent.Width;
                    }),
                    Constraint.RelativeToParent((parent) =>
                    {
                        return 50;
                    })
                );
            }
        

            Content = rLmenu;
        }
Example #8
0
 public SearchBarEvents(SearchBar This)
     : base(This)
 {
     this.This = This;
 }
Example #9
0
 public static SearchBarEvents Events(this SearchBar This)
 {
     return(new SearchBarEvents(This));
 }
        /* MainPage2_PopupPage 시작 */
        public MainPage2_PickerPage()
        {
            // ios modal 스타일 설정
            On <iOS>().SetModalPresentationStyle(UIModalPresentationStyle.Automatic);



            // 상단 왼쪽 취소 버튼
            var cancelButton = new Button
            {
                Text              = "Cancel",
                BackgroundColor   = Color.FromHex("#EEEEEE"),
                TextColor         = Color.FromHex("#8B00FF"),
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(20, 0, 0, 0)
            };

            cancelButton.Clicked += OnCancel;

            // 상단 가운데 타이틀
            var titleLabel = new Label
            {
                Text                    = "Select Category",
                TextColor               = Color.Black,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                VerticalOptions         = LayoutOptions.FillAndExpand,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize                = 16
            };

            // 상단 타이틀바 Grid (3X1)
            var grid = new Grid
            {
                ColumnDefinitions =
                {
                    new ColumnDefinition(),
                    new ColumnDefinition(),
                    new ColumnDefinition()
                },
                VerticalOptions = LayoutOptions.FillAndExpand,
            };

            grid.Children.Add(cancelButton, 0, 0);
            grid.Children.Add(titleLabel, 1, 0);


            // 타이틀바 + CollectionView(Picker)가 들어갈 stacklayout 정의
            var modalLayout = new StackLayout
            {
                Orientation       = StackOrientation.Vertical,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          =
                {
                    // 배경색상
                    new StackLayout
                    {
                        BackgroundColor      = Color.FromHex("#EEEEEE"),
                        Orientation          = StackOrientation.Vertical,
                        VerticalOptions      = LayoutOptions.Start,
                        HorizontalOptions    = LayoutOptions.FillAndExpand,
                        HeightRequest        = 50,
                        MinimumHeightRequest = 50,
                        Children             =
                        {
                            grid // 타이틀바 추가
                        }
                    }
                }
            };

            /* collectionView 시작 */
            var collectionView = new CollectionView                        // Picker가 될 Collection View
            {
                EmptyView       = "없네요 ㅎ",                                 // 데이터 없을때
                Margin          = new Thickness(0, 0, 0, 20),              // 아이폰 네비게이션바 안겹치게
                ItemsSource     = CustomPickerViewModel.CustomPickerItems, // 목록 항목들
                VerticalOptions = LayoutOptions.FillAndExpand,             // 아래 빈공간 없앰
                //  ItemsLayout = new GridItemsLayout(2, ItemsLayoutOrientation.Vertical), // 2줄로
                //  {
                //      VerticalItemSpacing = 20,
                //      HorizontalItemSpacing = 30
                //  },
                //  ItemSizingStrategy = ItemSizingStrategy.MeasureAllItems,

                /* ItemTemplate 시작 */
                ItemTemplate = new DataTemplate(() =>
                {
                    // 목록들이 들어갈 Grid (한 목록당 3행 2열)
                    Grid itemGrid = new Grid
                    {
                        //Padding = 15,
                        RowDefinitions =
                        {
                            new RowDefinition // 첫 번째 줄
                            {
                                Height = GridLength.Auto
                            },
                            new RowDefinition // 두 번째 줄
                            {
                                Height = GridLength.Auto
                            }
                        },
                        ColumnDefinitions =
                        {
                            // 3행
                            new ColumnDefinition(),
                            new ColumnDefinition(),
                            new ColumnDefinition()
                        }
                    };

                    // 목록 아이콘
                    Image image = new Image
                    {
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        Aspect            = Aspect.AspectFit,
                        HeightRequest     = 52,
                        WidthRequest      = 52
                    };
                    image.SetBinding(Image.SourceProperty, "imagesource");
                    itemGrid.Children.Add(image, 0, 0);

                    /*
                     * // 아이콘 설명 라벨 배경
                     * BoxView labelBox = new BoxView
                     * {
                     *  BackgroundColor = Color.White,
                     *  HorizontalOptions = LayoutOptions.FillAndExpand,
                     *  VerticalOptions = LayoutOptions.FillAndExpand,
                     * };
                     * Grid.SetRow(labelBox, 1); // 1열, 아이콘 아래
                     * itemGrid.Children.Add(labelBox);
                     */

                    // 아이콘 설명 라벨
                    Label imageLabel = new Label()
                    {
                        HorizontalOptions = LayoutOptions.Center,
                        VerticalOptions   = LayoutOptions.Start,
                        //TextColor = Color.Black,
                        FontSize = 12
                    };
                    imageLabel.SetBinding(Label.TextProperty, "imagesource");
                    Grid.SetRow(imageLabel, 1); // 1열, 아이콘 아래
                    itemGrid.Children.Add(imageLabel);

                    // 목록 이름
                    Label nameLabel = new Label()
                    {
                        HorizontalOptions     = LayoutOptions.CenterAndExpand,
                        VerticalOptions       = LayoutOptions.CenterAndExpand,
                        VerticalTextAlignment = TextAlignment.Center,
                        //TextColor = Color.Black,
                        //BackgroundColor=Color.SteelBlue,
                        FontSize = Device.GetNamedSize(NamedSize.Body, typeof(Label))
                    };

                    // 목록 이름과 색상을 바인딩
                    nameLabel.SetBinding(Label.TextProperty, "name");
                    // nameLabel.SetBinding(Label.TextColorProperty, "color"); // 목록 이름 색상 설정
                    Grid.SetColumn(nameLabel, 1);  // 0열, 1행에 위치
                    Grid.SetRowSpan(nameLabel, 2); // 2열 차지(중앙에 위치 위해서)
                    // Grid.SetColumnSpan(nameLabel, 2); // 2행 차지(중앙에 위치 위해서)
                    itemGrid.Children.Add(nameLabel);

                    // itemGrid.SetBinding(Grid.BackgroundColorProperty, "color");



                    Frame gridFrame = new Frame
                    {
                        BorderColor  = Color.FromHex("#EEEEEE"),
                        HasShadow    = false,
                        Content      = itemGrid,
                        CornerRadius = 0
                    };

                    // 목록 클릭 이벤트 설정 (TapGestureRecognizer)
                    var tapGestureRecognizer     = new TapGestureRecognizer();
                    tapGestureRecognizer.Tapped += (s, e) =>
                    {
                        //gridFrame.BackgroundColor = Color.Orange;
                        OnCollcetionViewItemSelected(nameLabel.Text, (FileImageSource)image.Source); // 목록 이름과 아이콘
                    };
                    gridFrame.GestureRecognizers.Add(tapGestureRecognizer);                          // Grid에 만든 탭제스처 추가

                    return(gridFrame);
                })
                               /* ItemTemplate 끝 */
            };
            /* collectionView 끝 */

            // 목록 검색창
            var searchBar = new Xamarin.Forms.SearchBar
            {
                Margin           = 0,
                Placeholder      = "Search items...",
                PlaceholderColor = Color.Silver,
                TextColor        = Color.Black,
                //HorizontalTextAlignment = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Xamarin.Forms.SearchBar)),
                // FontAttributes = FontAttributes.Italic
            };

            // 검색창 텍스트 입력시 이벤트
            searchBar.TextChanged += (sender, e) =>
            {
                collectionView.ScrollTo(0); //검색내용 맨 위부터 보이게
                //Xamarin.Forms.SearchBar searchBar2 = (Xamarin.Forms.SearchBar)sender;
                collectionView.ItemsSource = GetSearchResults(e.NewTextValue);
            };

            modalLayout.Children.Add(searchBar);      // 피커 목록 검색창
            modalLayout.Children.Add(collectionView); // 피커 목록

            Content = modalLayout;
        }
        // Constructor de la "View"
        public HomePage()
        {
            stackLayoutGrid = new StackLayout();

            //Inicializar lista
            ListItems = IniciListItems();

            // Título de la aplicación
            this.Title           = "TeeChart DEMO";
            this.BackgroundColor = Color.FromRgb(240, 240, 240);
            if (Device.RuntimePlatform == Device.Android)
            {
                this.IconImageSource = new FileImageSource {
                    File = "home_black_36dp.png"
                }
            }
            ;
            else
            {
                this.IconImageSource = new FileImageSource {
                    File = "mic_home_black_36dp.png"
                }
            };

            // Características de la "App" según el dispositivo
            switch (Device.RuntimePlatform)
            {
            case Device.Android:
                lView.Margin = new Thickness(5, 0, 5, 0);
                break;

            case Device.iOS:
                searchBar = new Xamarin.Forms.SearchBar();
                searchBar.BackgroundColor = Color.White;
                searchBar.TextChanged    += sBar_TextChanged;
                On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
                //InitializeToolbarItem();
                break;
            }

            // Propiedades "listView"
            lView.ItemsSource = ListItems;
            if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.UWP)
            {
                lView.RowHeight = 120;
            }
            else
            {
                lView.RowHeight = 110;
            }

            lView.ItemSelected       += (sender, e) => { ((Xamarin.Forms.ListView)sender).SelectedItem = null; };
            lView.ItemTapped         += ItemsListView_ChangeActivity;
            lView.SeparatorVisibility = SeparatorVisibility.None;
            DataTemplatelView();
            ListViewCachingStrategy.RetainElement.Equals(lView);

            // Mostrar elementos
            stackLayoutGrid = new StackLayout();
            stackLayoutGrid.VerticalOptions = LayoutOptions.FillAndExpand;
            if (Device.RuntimePlatform == Device.iOS)
            {
                stackLayoutGrid.Children.Add(searchBar);
            }
            stackLayoutGrid.Children.Add(lView);
            stackLayoutGrid.Margin  = 0;
            stackLayoutGrid.Spacing = 0;

            // Condiciones para algunos elementos
            if (vm == null)
            {
                ViewModel = new HomeViewModel();
            }

            this.ListView  = lView;
            base.ListItems = this.ListItems;
        }