void MoveElementTo(View element, Layout <View> to) { Device.BeginInvokeOnMainThread(() => { if (Element.Parent is Layout <View> layout) { var index = layout.Children.IndexOf(element); layout.Children.Insert(index, to); if (layout is Grid) { var row = Grid.GetRow(element); var rowSpan = Grid.GetRowSpan(element); var column = Grid.GetColumn(element); var columnSpan = Grid.GetColumnSpan(element); Grid.SetRow(to, row); Grid.SetRowSpan(to, rowSpan); Grid.SetColumn(to, column); Grid.SetColumnSpan(to, columnSpan); } } else if (Element.Parent is ScrollView scrollView) { scrollView.Content = to; } else if (Element.Parent is ContentView contentView) { contentView.Content = to; } to.Children.Add(element); }); }
static SearchView() { ImageSourceConverter = new ByteArrayToImageSourceConverter(); CollectionIconConverter = new BoolToCollectionIconImageConverter(); EmptyStringConverter = new EmptyStringToBoolConverter(); DefaultSuggestionGroupHeaderTemplate = new DataTemplate(() => { var viewcell = new ViewCell(); Grid containingGrid = new Grid(); containingGrid.BackgroundColor = Color.FromHex("#4e4e4e"); Label textLabel = new Label(); textLabel.SetBinding(Label.TextProperty, "Key.DisplayName"); textLabel.Margin = new Thickness(4); textLabel.TextColor = Color.White; textLabel.FontSize = 14; textLabel.VerticalTextAlignment = TextAlignment.Center; containingGrid.Children.Add(textLabel); viewcell.View = containingGrid; return(viewcell); }); DefaultSuggestionTemplate = new DataTemplate(() => { var viewCell = new ViewCell(); Grid containingGrid = new Grid(); containingGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); containingGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); containingGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); Grid textStack = new Grid(); textStack.VerticalOptions = LayoutOptions.Center; textStack.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); textStack.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); Image imageView = new Image(); imageView.SetBinding(Image.SourceProperty, nameof(SearchSuggestion.IsCollection), converter: CollectionIconConverter); imageView.WidthRequest = 16; imageView.HeightRequest = 16; imageView.Margin = new Thickness(4); imageView.VerticalOptions = LayoutOptions.Center; Label titleLabel = new Label(); titleLabel.SetBinding(Label.TextProperty, nameof(SearchSuggestion.DisplayTitle)); titleLabel.VerticalOptions = LayoutOptions.End; titleLabel.VerticalTextAlignment = TextAlignment.End; titleLabel.TextColor = Color.Black; Label subtitleLabel = new Label(); subtitleLabel.SetBinding(Label.TextProperty, nameof(SearchSuggestion.DisplaySubtitle)); subtitleLabel.SetBinding(Label.IsVisibleProperty, nameof(SearchSuggestion.DisplaySubtitle), converter: EmptyStringConverter); subtitleLabel.VerticalOptions = LayoutOptions.Start; subtitleLabel.VerticalTextAlignment = TextAlignment.Start; subtitleLabel.TextColor = Color.Black; textStack.Children.Add(titleLabel); textStack.Children.Add(subtitleLabel); Grid.SetRow(titleLabel, 0); Grid.SetRow(subtitleLabel, 1); containingGrid.Children.Add(imageView); containingGrid.Children.Add(textStack); Grid.SetColumn(textStack, 1); Grid.SetColumn(imageView, 0); viewCell.View = containingGrid; return(viewCell); }); DefaultResultTemplate = new DataTemplate(() => { var viewCell = new ViewCell(); Grid containingGrid = new Grid(); containingGrid.Padding = new Thickness(2, 4, 2, 4); containingGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); containingGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); containingGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); Grid textStack = new Grid(); textStack.VerticalOptions = LayoutOptions.Center; textStack.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); textStack.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); Image imageView = new Image(); imageView.SetBinding(Image.SourceProperty, nameof(SearchResult.MarkerImageData), converter: ImageSourceConverter); imageView.WidthRequest = 24; imageView.HeightRequest = 24; imageView.Margin = new Thickness(4); imageView.VerticalOptions = LayoutOptions.Center; Label titleLabel = new Label(); titleLabel.SetBinding(Label.TextProperty, nameof(SearchResult.DisplayTitle)); titleLabel.FontAttributes = FontAttributes.Bold; titleLabel.VerticalOptions = LayoutOptions.End; titleLabel.VerticalTextAlignment = TextAlignment.End; titleLabel.TextColor = Color.Black; Label subtitleLabel = new Label(); subtitleLabel.SetBinding(Label.TextProperty, nameof(SearchResult.DisplaySubtitle)); subtitleLabel.SetBinding(Label.IsVisibleProperty, nameof(SearchResult.DisplaySubtitle), converter: EmptyStringConverter); subtitleLabel.TextColor = Color.Black; subtitleLabel.VerticalOptions = LayoutOptions.Start; subtitleLabel.VerticalTextAlignment = TextAlignment.Start; textStack.Children.Add(titleLabel); textStack.Children.Add(subtitleLabel); Grid.SetRow(titleLabel, 0); Grid.SetRow(subtitleLabel, 1); containingGrid.Children.Add(imageView); containingGrid.Children.Add(textStack); Grid.SetColumn(textStack, 1); Grid.SetColumn(imageView, 0); viewCell.View = containingGrid; return(viewCell); }); string template = $@"<ControlTemplate xmlns=""http://xamarin.com/schemas/2014/forms"" xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" xmlns:esriTK=""clr-namespace:Esri.ArcGISRuntime.Toolkit.Xamarin.Forms""> <Grid RowSpacing=""0"" ColumnSpacing=""0"" > <Grid.ColumnDefinitions> <ColumnDefinition Width=""Auto"" /> <ColumnDefinition Width=""*"" /> <ColumnDefinition Width=""32"" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height=""Auto"" /> <RowDefinition Height=""Auto"" /> <RowDefinition Height=""Auto"" /> </Grid.RowDefinitions> <Grid Grid.Row=""0"" Grid.ColumnSpan=""3"" BackgroundColor=""White"" /> <ImageButton x:Name=""{nameof(PART_SourceSelectButton)}"" Grid.Column=""0"" WidthRequest=""32"" HeightRequest=""32"" Padding=""4"" BackgroundColor=""Transparent"" Margin=""0"" /> <Entry x:Name=""{nameof(PART_Entry)}"" Grid.Column=""1"" Grid.Row=""0"" BackgroundColor=""White"" TextColor=""Black"" /> <ImageButton x:Name=""{nameof(PART_CancelButton)}"" Grid.Column=""1"" HorizontalOptions=""End"" WidthRequest=""32"" HeightRequest=""32"" Padding=""4"" BackgroundColor=""Transparent"" /> <ImageButton x:Name=""{nameof(PART_SearchButton)}"" Grid.Column=""2"" WidthRequest=""32"" HeightRequest=""32"" Padding=""4"" BackgroundColor=""Transparent"" /> <ListView x:Name=""{nameof(PART_SuggestionsView)}"" Grid.Column=""0"" Grid.ColumnSpan=""3"" Grid.Row=""1"" Grid.RowSpan=""2"" HasUnevenRows=""true"" BackgroundColor=""White"" HeightRequest=""175"" /> <ListView x:Name=""{nameof(PART_ResultView)}"" Grid.Column=""0"" Grid.ColumnSpan=""3"" Grid.Row=""1"" Grid.RowSpan=""1"" HasUnevenRows=""true"" BackgroundColor=""White"" HeightRequest=""200"" /> <ListView x:Name=""{nameof(PART_SourcesView)}"" Grid.Column=""0"" Grid.ColumnSpan=""3"" Grid.Row=""1"" BackgroundColor=""White"" HeightRequest=""150"" /> <Grid x:Name=""{nameof(PART_ResultContainer)}"" BackgroundColor=""White"" Grid.ColumnSpan=""3"" Grid.Row=""1"" Padding=""8""><Label x:Name=""{nameof(PART_ResultLabel)}"" HorizontalOptions=""Center"" VerticalOptions=""Center"" FontAttributes=""Bold"" /></Grid> <Grid x:Name=""{nameof(PART_RepeatButtonContainer)}"" BackgroundColor=""White"" Grid.Column=""0"" Grid.ColumnSpan=""3"" Grid.Row=""2""> <Button x:Name=""{nameof(PART_RepeatButton)}"" BackgroundColor=""#007AC2"" TextColor=""White"" CornerRadius=""0"" /> </Grid> </Grid> </ControlTemplate>"; DefaultControlTemplate = XForms.Extensions.LoadFromXaml(new ControlTemplate(), template); }