/// <summary>
        /// Creates container controls for a collection of items.
        /// </summary>
        /// <param name="startingIndex">
        /// The index of the first item of the data in the containing collection.
        /// </param>
        /// <param name="items">The items.</param>
        /// <param name="itemTemplate">An optional item template.</param>
        /// <returns>The created container controls.</returns>
        public IList<IControl> CreateContainers(
            int startingIndex,
            IEnumerable items,
            IDataTemplate itemTemplate)
        {
            Contract.Requires<ArgumentNullException>(items != null);

            int index = startingIndex;
            var result = new List<IControl>();

            foreach (var item in items)
            {
                IControl container = CreateContainer(item, itemTemplate);
                result.Add(container);
            }

            AddContainers(startingIndex, result);
            _containersInitialized.OnNext(new ItemContainers(startingIndex, result));

            return result.Where(x => x != null).ToList();
        }
        /// <summary>
        /// Find a data template that matches a piece of data.
        /// </summary>
        /// <param name="control">The control searching for the data template.</param>
        /// <param name="data">The data.</param>
        /// <param name="primary">
        /// An optional primary template that can will be tried before the
        /// <see cref="IControl.DataTemplates"/> in the tree are searched.
        /// </param>
        /// <returns>The data template or null if no matching data template was found.</returns>
        public static IDataTemplate FindDataTemplate(
            this IControl control,
            object data,
            IDataTemplate primary = null)
        {
            if (primary?.Match(data) == true)
            {
                return primary;
            }

            foreach (var i in control.GetSelfAndLogicalAncestors().OfType<IControl>())
            {
                foreach (IDataTemplate dt in i.DataTemplates)
                {
                    if (dt.Match(data))
                    {
                        return dt;
                    }
                }
            }

            IGlobalDataTemplates global = AvaloniaLocator.Current.GetService<IGlobalDataTemplates>();

            if (global != null)
            {
                foreach (IDataTemplate dt in global.DataTemplates)
                {
                    if (dt.Match(data))
                    {
                        return dt;
                    }
                }
            }

            return null;
        }
Example #3
0
        /// <summary>
        /// Creates the child control.
        /// </summary>
        /// <returns>The child control or null.</returns>
        protected virtual IControl CreateChild()
        {
            var content = Content;
            var oldChild = Child;
            var newChild = content as IControl;

            if (content != null && newChild == null)
            {
                // We have content and it isn't a control, so first try to recycle the existing
                // child control to display the new data by querying if the template that created
                // the child can recycle items and that it also matches the new data.
                if (oldChild != null &&
                    _dataTemplate != null &&
                    _dataTemplate.SupportsRecycling &&
                    _dataTemplate.Match(content))
                {
                    newChild = oldChild;
                }
                else
                {
                    // We couldn't recycle an existing control so find a data template for the data
                    // and use it to create a control.
                    _dataTemplate = this.FindDataTemplate(content, ContentTemplate) ?? FuncDataTemplate.Default;
                    newChild = _dataTemplate.Build(content);

                    // Try to give the new control its own name scope.
                    var controlResult = newChild as Control;

                    if (controlResult != null)
                    {
                        NameScope.SetNameScope(controlResult, new NameScope());
                    }
                }
            }
            else
            {
                _dataTemplate = null;
            }

            return newChild;
        }
Example #4
0
 /// <inheritdoc/>
 protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
     base.OnAttachedToVisualTree(e);
     _dataTemplate = null;
 }
 /// <summary>
 /// Creates the container for an item.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="itemTemplate">An optional item template.</param>
 /// <returns>The created container control.</returns>
 protected virtual IControl CreateContainer(object item, IDataTemplate itemTemplate)
 {
     if (item == null)
     {
         return null;
     }
     else if (itemTemplate != null && itemTemplate.Match(item))
     {
         var result = itemTemplate.Build(item);
         result.DataContext = item;
         return result;
     }
     else
     {
         return Owner.MaterializeDataTemplate(item);
     }
 }
Example #6
0
 /// <inheritdoc/>
 protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
     base.OnAttachedToVisualTree(e);
     _dataTemplate = null;
 }
Example #7
0
        private void InitializeComponent()
        {
            if (ResourceLoader.ResourceProvider != null && ResourceLoader.ResourceProvider(typeof(QueryUploadPage).GetTypeInfo().Assembly.GetName(), "Views/QueryUploadPage.xaml") != null)
            {
                this.__InitComponentRuntime();
                return;
            }
            if (XamlLoader.XamlFileProvider != null && XamlLoader.XamlFileProvider(base.GetType()) != null)
            {
                this.__InitComponentRuntime();
                return;
            }
            BindingExtension  bindingExtension  = new BindingExtension();
            ColumnDefinition  columnDefinition  = new ColumnDefinition();
            ColumnDefinition  columnDefinition2 = new ColumnDefinition();
            RowDefinition     rowDefinition     = new RowDefinition();
            Label             label             = new Label();
            Label             label2            = new Label();
            Grid              grid = new Grid();
            BindingExtension  bindingExtension2 = new BindingExtension();
            DataTemplate      dataTemplate      = new DataTemplate();
            ListView          listView          = new ListView();
            StackLayout       stackLayout       = new StackLayout();
            BindingExtension  bindingExtension3 = new BindingExtension();
            BindingExtension  bindingExtension4 = new BindingExtension();
            ActivityIndicator activityIndicator = new ActivityIndicator();
            Grid              grid2             = new Grid();
            NameScope         nameScope         = new NameScope();

            NameScope.SetNameScope(this, nameScope);
            NameScope.SetNameScope(grid2, nameScope);
            NameScope.SetNameScope(stackLayout, nameScope);
            NameScope.SetNameScope(grid, nameScope);
            NameScope.SetNameScope(columnDefinition, nameScope);
            NameScope.SetNameScope(columnDefinition2, nameScope);
            NameScope.SetNameScope(rowDefinition, nameScope);
            NameScope.SetNameScope(label, nameScope);
            NameScope.SetNameScope(label2, nameScope);
            NameScope.SetNameScope(listView, nameScope);
            NameScope.SetNameScope(activityIndicator, nameScope);
            bindingExtension.Path = "Title";
            BindingBase binding = ((IMarkupExtension <BindingBase>)bindingExtension).ProvideValue(null);

            this.SetBinding(Page.TitleProperty, binding);
            stackLayout.SetValue(Xamarin.Forms.Layout.PaddingProperty, new Thickness(0.0));
            stackLayout.SetValue(StackLayout.SpacingProperty, 0.0);
            grid.SetValue(VisualElement.BackgroundColorProperty, Color.Silver);
            grid.SetValue(Grid.RowSpacingProperty, 5.0);
            grid.SetValue(Xamarin.Forms.Layout.PaddingProperty, new Thickness(10.0, 5.0, 10.0, 5.0));
            columnDefinition.SetValue(ColumnDefinition.WidthProperty, new GridLengthTypeConverter().ConvertFromInvariantString("*"));
            grid.GetValue(Grid.ColumnDefinitionsProperty).Add(columnDefinition);
            columnDefinition2.SetValue(ColumnDefinition.WidthProperty, new GridLengthTypeConverter().ConvertFromInvariantString("3*"));
            grid.GetValue(Grid.ColumnDefinitionsProperty).Add(columnDefinition2);
            rowDefinition.SetValue(RowDefinition.HeightProperty, new GridLengthTypeConverter().ConvertFromInvariantString("40"));
            grid.GetValue(Grid.RowDefinitionsProperty).Add(rowDefinition);
            label.SetValue(Grid.ColumnProperty, 0);
            label.SetValue(Label.TextProperty, "运单描述");
            label.SetValue(Label.TextColorProperty, new Color(0.501960813999176, 0.501960813999176, 0.501960813999176, 1.0));
            BindableObject         bindableObject        = label;
            BindableProperty       fontSizeProperty      = Label.FontSizeProperty;
            IExtendedTypeConverter extendedTypeConverter = new FontSizeConverter();
            string value = "Default";
            XamlServiceProvider xamlServiceProvider = new XamlServiceProvider();
            Type typeFromHandle = typeof(IProvideValueTarget);

            object[] array = new object[0 + 5];
            array[0] = label;
            array[1] = grid;
            array[2] = stackLayout;
            array[3] = grid2;
            array[4] = this;
            xamlServiceProvider.Add(typeFromHandle, new SimpleValueTargetProvider(array, Label.FontSizeProperty));
            xamlServiceProvider.Add(typeof(INameScopeProvider), new NameScopeProvider
            {
                NameScope = nameScope
            });
            Type typeFromHandle2 = typeof(IXamlTypeResolver);
            XmlNamespaceResolver xmlNamespaceResolver = new XmlNamespaceResolver();

            xmlNamespaceResolver.Add("", "http://xamarin.com/schemas/2014/forms");
            xmlNamespaceResolver.Add("x", "http://schemas.microsoft.com/winfx/2009/xaml");
            xmlNamespaceResolver.Add("layout", "clr-namespace:RFID.Layout");
            xamlServiceProvider.Add(typeFromHandle2, new XamlTypeResolver(xmlNamespaceResolver, typeof(QueryUploadPage).GetTypeInfo().Assembly));
            xamlServiceProvider.Add(typeof(IXmlLineInfoProvider), new XmlLineInfoProvider(new XmlLineInfo(16, 75)));
            bindableObject.SetValue(fontSizeProperty, extendedTypeConverter.ConvertFromInvariantString(value, xamlServiceProvider));
            label.SetValue(View.HorizontalOptionsProperty, LayoutOptions.FillAndExpand);
            label.SetValue(View.VerticalOptionsProperty, LayoutOptions.Center);
            label.SetValue(Label.HorizontalTextAlignmentProperty, new TextAlignmentConverter().ConvertFromInvariantString("Start"));
            grid.Children.Add(label);
            label2.SetValue(Grid.ColumnProperty, 1);
            label2.SetValue(Label.TextProperty, "运单照片");
            BindableObject         bindableObject2        = label2;
            BindableProperty       fontSizeProperty2      = Label.FontSizeProperty;
            IExtendedTypeConverter extendedTypeConverter2 = new FontSizeConverter();
            string value2 = "Default";
            XamlServiceProvider xamlServiceProvider2 = new XamlServiceProvider();
            Type typeFromHandle3 = typeof(IProvideValueTarget);

            object[] array2 = new object[0 + 5];
            array2[0] = label2;
            array2[1] = grid;
            array2[2] = stackLayout;
            array2[3] = grid2;
            array2[4] = this;
            xamlServiceProvider2.Add(typeFromHandle3, new SimpleValueTargetProvider(array2, Label.FontSizeProperty));
            xamlServiceProvider2.Add(typeof(INameScopeProvider), new NameScopeProvider
            {
                NameScope = nameScope
            });
            Type typeFromHandle4 = typeof(IXamlTypeResolver);
            XmlNamespaceResolver xmlNamespaceResolver2 = new XmlNamespaceResolver();

            xmlNamespaceResolver2.Add("", "http://xamarin.com/schemas/2014/forms");
            xmlNamespaceResolver2.Add("x", "http://schemas.microsoft.com/winfx/2009/xaml");
            xmlNamespaceResolver2.Add("layout", "clr-namespace:RFID.Layout");
            xamlServiceProvider2.Add(typeFromHandle4, new XamlTypeResolver(xmlNamespaceResolver2, typeof(QueryUploadPage).GetTypeInfo().Assembly));
            xamlServiceProvider2.Add(typeof(IXmlLineInfoProvider), new XmlLineInfoProvider(new XmlLineInfo(17, 61)));
            bindableObject2.SetValue(fontSizeProperty2, extendedTypeConverter2.ConvertFromInvariantString(value2, xamlServiceProvider2));
            label2.SetValue(Label.TextColorProperty, Color.Black);
            label2.SetValue(View.HorizontalOptionsProperty, LayoutOptions.FillAndExpand);
            label2.SetValue(View.VerticalOptionsProperty, LayoutOptions.Center);
            grid.Children.Add(label2);
            stackLayout.Children.Add(grid);
            listView.SetValue(ListView.SelectionModeProperty, ListViewSelectionMode.None);
            listView.SetValue(ListView.RowHeightProperty, 90);
            bindingExtension2.Path = "QueryWaybills";
            BindingBase binding2 = ((IMarkupExtension <BindingBase>)bindingExtension2).ProvideValue(null);

            listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, binding2);
            IDataTemplate dataTemplate2 = dataTemplate;

            QueryUploadPage.< InitializeComponent > _anonXamlCDataTemplate_3 <InitializeComponent> _anonXamlCDataTemplate_ = new QueryUploadPage.< InitializeComponent > _anonXamlCDataTemplate_3();
            object[]          array3 = new object[0 + 5];
            array3[0] = dataTemplate;
            array3[1] = listView;
            array3[2] = stackLayout;
            array3[3] = grid2;
            array3[4] = this;
Example #8
0
 public ContentDialogService(Window owner, IDataTemplate viewResolver)
 {
     _owner        = owner;
     _viewResolver = viewResolver;
 }
Example #9
0
        private void InitializeComponent()
        {
            if (ResourceLoader.ResourceProvider != null && ResourceLoader.ResourceProvider(typeof(DriverPage).GetTypeInfo().Assembly.GetName(), "Views/DriverPage.xaml") != null)
            {
                this.__InitComponentRuntime();
                return;
            }
            if (XamlLoader.XamlFileProvider != null && XamlLoader.XamlFileProvider(base.GetType()) != null)
            {
                this.__InitComponentRuntime();
                return;
            }
            BindingExtension       bindingExtension       = new BindingExtension();
            RowDefinition          rowDefinition          = new RowDefinition();
            RowDefinition          rowDefinition2         = new RowDefinition();
            ColumnDefinition       columnDefinition       = new ColumnDefinition();
            ColumnDefinition       columnDefinition2      = new ColumnDefinition();
            BindingExtension       bindingExtension2      = new BindingExtension();
            TranslateExtension     translateExtension     = new TranslateExtension();
            BindingExtension       bindingExtension3      = new BindingExtension();
            BindingExtension       bindingExtension4      = new BindingExtension();
            EventToCommandBehavior eventToCommandBehavior = new EventToCommandBehavior();
            SearchBar            searchBar            = new SearchBar();
            BindingExtension     bindingExtension5    = new BindingExtension();
            TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();
            SvgCachedImage       svgCachedImage       = new SvgCachedImage();
            Grid                   grid = new Grid();
            BindingExtension       bindingExtension6       = new BindingExtension();
            BindingExtension       bindingExtension7       = new BindingExtension();
            EventToCommandBehavior eventToCommandBehavior2 = new EventToCommandBehavior();
            DataTemplate           dataTemplate            = new DataTemplate();
            ListView               listView  = new ListView();
            Grid                   grid2     = new Grid();
            NameScope              nameScope = new NameScope();

            NameScope.SetNameScope(this, nameScope);
            NameScope.SetNameScope(grid2, nameScope);
            NameScope.SetNameScope(rowDefinition, nameScope);
            NameScope.SetNameScope(rowDefinition2, nameScope);
            NameScope.SetNameScope(grid, nameScope);
            NameScope.SetNameScope(columnDefinition, nameScope);
            NameScope.SetNameScope(columnDefinition2, nameScope);
            NameScope.SetNameScope(searchBar, nameScope);
            NameScope.SetNameScope(eventToCommandBehavior, nameScope);
            NameScope.SetNameScope(svgCachedImage, nameScope);
            NameScope.SetNameScope(tapGestureRecognizer, nameScope);
            NameScope.SetNameScope(listView, nameScope);
            ((INameScope)nameScope).RegisterName("listview", listView);
            if (listView.StyleId == null)
            {
                listView.StyleId = "listview";
            }
            NameScope.SetNameScope(eventToCommandBehavior2, nameScope);
            this.listview = listView;
            this.SetValue(ViewModelLocator.AutowireViewModelProperty, new bool?(true));
            bindingExtension.Path = "Title";
            BindingBase binding = ((IMarkupExtension <BindingBase>)bindingExtension).ProvideValue(null);

            this.SetBinding(Page.TitleProperty, binding);
            rowDefinition.SetValue(RowDefinition.HeightProperty, new GridLengthTypeConverter().ConvertFromInvariantString("Auto"));
            grid2.GetValue(Grid.RowDefinitionsProperty).Add(rowDefinition);
            rowDefinition2.SetValue(RowDefinition.HeightProperty, new GridLengthTypeConverter().ConvertFromInvariantString("*"));
            grid2.GetValue(Grid.RowDefinitionsProperty).Add(rowDefinition2);
            grid.SetValue(Grid.RowProperty, 0);
            grid.SetValue(VisualElement.BackgroundColorProperty, Color.White);
            grid.SetValue(Xamarin.Forms.Layout.PaddingProperty, new Thickness(10.0));
            grid.SetValue(Grid.ColumnSpacingProperty, 10.0);
            columnDefinition.SetValue(ColumnDefinition.WidthProperty, new GridLengthTypeConverter().ConvertFromInvariantString("*"));
            grid.GetValue(Grid.ColumnDefinitionsProperty).Add(columnDefinition);
            columnDefinition2.SetValue(ColumnDefinition.WidthProperty, new GridLengthTypeConverter().ConvertFromInvariantString("24"));
            grid.GetValue(Grid.ColumnDefinitionsProperty).Add(columnDefinition2);
            searchBar.SetValue(Grid.ColumnProperty, 0);
            bindingExtension2.Path = "SearchText";
            BindingBase binding2 = ((IMarkupExtension <BindingBase>)bindingExtension2).ProvideValue(null);

            searchBar.SetBinding(SearchBar.TextProperty, binding2);
            translateExtension.Text = "search";
            IMarkupExtension    markupExtension     = translateExtension;
            XamlServiceProvider xamlServiceProvider = new XamlServiceProvider();
            Type typeFromHandle = typeof(IProvideValueTarget);

            object[] array = new object[0 + 4];
            array[0] = searchBar;
            array[1] = grid;
            array[2] = grid2;
            array[3] = this;
            xamlServiceProvider.Add(typeFromHandle, new SimpleValueTargetProvider(array, SearchBar.PlaceholderProperty));
            xamlServiceProvider.Add(typeof(INameScopeProvider), new NameScopeProvider
            {
                NameScope = nameScope
            });
            Type typeFromHandle2 = typeof(IXamlTypeResolver);
            XmlNamespaceResolver xmlNamespaceResolver = new XmlNamespaceResolver();

            xmlNamespaceResolver.Add("", "http://xamarin.com/schemas/2014/forms");
            xmlNamespaceResolver.Add("x", "http://schemas.microsoft.com/winfx/2009/xaml");
            xmlNamespaceResolver.Add("prism", "clr-namespace:Prism.Mvvm;assembly=Prism.Forms");
            xmlNamespaceResolver.Add("local", "clr-namespace:RFID");
            xmlNamespaceResolver.Add("b", "clr-namespace:Prism.Behaviors;assembly=Prism.Forms");
            xmlNamespaceResolver.Add("svg", "clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms");
            xamlServiceProvider.Add(typeFromHandle2, new XamlTypeResolver(xmlNamespaceResolver, typeof(DriverPage).GetTypeInfo().Assembly));
            xamlServiceProvider.Add(typeof(IXmlLineInfoProvider), new XmlLineInfoProvider(new XmlLineInfo(21, 65)));
            object placeholder = markupExtension.ProvideValue(xamlServiceProvider);

            searchBar.Placeholder = placeholder;
            searchBar.SetValue(SearchBar.TextColorProperty, new Color(0.501960813999176, 0.501960813999176, 0.501960813999176, 1.0));
            bindingExtension3.Path = "SearchCommand";
            BindingBase binding3 = ((IMarkupExtension <BindingBase>)bindingExtension3).ProvideValue(null);

            searchBar.SetBinding(SearchBar.SearchCommandProperty, binding3);
            searchBar.SetValue(VisualElement.BackgroundColorProperty, new Color(0.93725490570068359, 0.93725490570068359, 0.93725490570068359, 1.0));
            eventToCommandBehavior.SetValue(EventToCommandBehavior.EventNameProperty, "TextChanged");
            bindingExtension4.Path = "SearchCommand";
            BindingBase binding4 = ((IMarkupExtension <BindingBase>)bindingExtension4).ProvideValue(null);

            eventToCommandBehavior.SetBinding(EventToCommandBehavior.CommandProperty, binding4);
            ((ICollection <Behavior>)searchBar.GetValue(VisualElement.BehaviorsProperty)).Add(eventToCommandBehavior);
            grid.Children.Add(searchBar);
            svgCachedImage.SetValue(Grid.ColumnProperty, 1);
            svgCachedImage.SetValue(VisualElement.WidthRequestProperty, 24.0);
            svgCachedImage.SetValue(VisualElement.HeightRequestProperty, 24.0);
            svgCachedImage.SetValue(CachedImage.SourceProperty, new FFImageLoading.Forms.ImageSourceConverter().ConvertFromInvariantString("plus.svg"));
            bindingExtension5.Path = "AddCommand";
            BindingBase binding5 = ((IMarkupExtension <BindingBase>)bindingExtension5).ProvideValue(null);

            tapGestureRecognizer.SetBinding(TapGestureRecognizer.CommandProperty, binding5);
            svgCachedImage.GestureRecognizers.Add(tapGestureRecognizer);
            grid.Children.Add(svgCachedImage);
            grid2.Children.Add(grid);
            listView.SetValue(Grid.RowProperty, 1);
            listView.SetValue(VisualElement.BackgroundColorProperty, new Color(0.98039215803146362, 0.98039215803146362, 0.98039215803146362, 1.0));
            bindingExtension6.Path = "SearchSource";
            BindingBase binding6 = ((IMarkupExtension <BindingBase>)bindingExtension6).ProvideValue(null);

            listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, binding6);
            listView.ItemSelected += this.Handle_ItemSelected;
            eventToCommandBehavior2.SetValue(EventToCommandBehavior.EventNameProperty, "ItemTapped");
            bindingExtension7.Path = "SelectCommand";
            BindingBase binding7 = ((IMarkupExtension <BindingBase>)bindingExtension7).ProvideValue(null);

            eventToCommandBehavior2.SetBinding(EventToCommandBehavior.CommandProperty, binding7);
            eventToCommandBehavior2.SetValue(EventToCommandBehavior.EventArgsParameterPathProperty, "Item");
            ((ICollection <Behavior>)listView.GetValue(VisualElement.BehaviorsProperty)).Add(eventToCommandBehavior2);
            IDataTemplate dataTemplate2 = dataTemplate;

            DriverPage.< InitializeComponent > _anonXamlCDataTemplate_6 <InitializeComponent> _anonXamlCDataTemplate_ = new DriverPage.< InitializeComponent > _anonXamlCDataTemplate_6();
            object[]     array2 = new object[0 + 4];
            array2[0] = dataTemplate;
            array2[1] = listView;
            array2[2] = grid2;
            array2[3] = this;
Example #10
0
 public ItemTemplateWrapper(IDataTemplate dataTemplate) => _dataTemplate = dataTemplate;