Beispiel #1
0
        static BasemapGallery()
        {
            OpacityConverter     = new BoolToOpacityConverter();
            ImageSourceConverter = new ByteArrayToImageSourceConverter();

            DefaultGridDataTemplate = new DataTemplate(() =>
            {
                Grid outerScrimContainer = new Grid();
                outerScrimContainer.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = 128
                });

                StackLayout parentLayout = new StackLayout()
                {
                    Orientation = StackOrientation.Vertical
                };
                parentLayout.Padding = new Thickness(8);
                Grid imageContainer  = new Grid {
                    Margin = new Thickness(0, 0, 0, 8)
                };
                Image fallback = new Image {
                    WidthRequest = 32, HeightRequest = 32, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center
                };
                fallback.Source = ImageSource.FromResource("Esri.ArcGISRuntime.Toolkit.Xamarin.Forms.Assets.BasemapLight.png", typeof(BasemapGallery).Assembly);
                Image thumbnail = new Image {
                    WidthRequest = 64, HeightRequest = 64, Aspect = Aspect.AspectFill
                };
                Label nameLabel = new Label {
                    FontSize = 11, TextColor = Color.FromHex("#6e6e6e"), HorizontalTextAlignment = TextAlignment.Center
                };
                imageContainer.Children.Add(fallback);
                imageContainer.Children.Add(thumbnail);
                parentLayout.Children.Add(imageContainer);
                parentLayout.Children.Add(nameLabel);

                Grid scrimGrid = new Grid {
                    BackgroundColor = Color.White
                };
                scrimGrid.SetValue(Grid.ColumnSpanProperty, 3);
                parentLayout.Children.Add(scrimGrid);

                outerScrimContainer.Children.Add(parentLayout);
                outerScrimContainer.Children.Add(scrimGrid);

                thumbnail.SetBinding(Image.SourceProperty, nameof(BasemapGalleryItem.ThumbnailData), converter: ImageSourceConverter);
                nameLabel.SetBinding(Label.TextProperty, nameof(BasemapGalleryItem.Name));
                scrimGrid.SetBinding(OpacityProperty, nameof(BasemapGalleryItem.IsValid), mode: BindingMode.OneWay, converter: OpacityConverter);

                return(outerScrimContainer);
            });

            DefaultListDataTemplate = new DataTemplate(() =>
            {
                Grid parentLayout = new Grid()
                {
                };
                parentLayout.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(8)
                });
                parentLayout.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(72)
                });
                parentLayout.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Star
                });

                Grid imageContainer = new Grid();
                Image fallback      = new Image {
                    WidthRequest = 32, HeightRequest = 32, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center
                };
                fallback.Source = ImageSource.FromResource("Esri.ArcGISRuntime.Toolkit.Xamarin.Forms.Assets.BasemapLight.png", typeof(BasemapGallery).Assembly);
                Image thumbnail = new Image {
                    WidthRequest = 64, HeightRequest = 64, Aspect = Aspect.AspectFill
                };
                Label nameLabel = new Label {
                    FontSize = 11, TextColor = Color.FromHex("#6e6e6e"), VerticalOptions = LayoutOptions.Center, VerticalTextAlignment = TextAlignment.Center
                };
                imageContainer.Children.Add(fallback);
                imageContainer.Children.Add(thumbnail);

                parentLayout.Children.Add(imageContainer);
                parentLayout.Children.Add(nameLabel);

                Grid scrimGrid = new Grid {
                    BackgroundColor = Color.White
                };
                scrimGrid.SetValue(Grid.ColumnSpanProperty, 3);
                parentLayout.Children.Add(scrimGrid);

                imageContainer.SetValue(Grid.ColumnProperty, 1);
                nameLabel.SetValue(Grid.ColumnProperty, 2);

                thumbnail.SetBinding(Image.SourceProperty, nameof(BasemapGalleryItem.ThumbnailData), converter: ImageSourceConverter);
                nameLabel.SetBinding(Label.TextProperty, nameof(BasemapGalleryItem.Name));
                scrimGrid.SetBinding(OpacityProperty, nameof(BasemapGalleryItem.IsValid), mode: BindingMode.OneWay, converter: OpacityConverter);

                return(parentLayout);
            });

            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>
                                        <CollectionView x:Name=""PART_InnerListView"" HorizontalOptions=""FillAndExpand"" VerticalOptions=""FillAndExpand"" SelectionMode=""Single"" />
                                        <Grid x:Name=""PART_LoadingScrim"">
                                            <Grid BackgroundColor=""{AppThemeBinding Light=White, Dark=Black}"" Opacity=""0.3"" />
                                            <ActivityIndicator IsRunning=""True"" HorizontalOptions=""Center"" VerticalOptions=""Center"" />
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>";

            DefaultControlTemplate = new ControlTemplate().LoadFromXaml(template);
        }
        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);
        }