Beispiel #1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            ScrollViewer = this.GetTemplateChild("ScrollViewer") as ScrollViewer;

            // NativePanel may not exist if we're using a non-virtualizing ItemsPanel.
            if (NativePanel != null)
            {
                NativePanel.XamlParent = this;
                // Propagate the DataContext manually, since ItemsPanelRoot isn't really part of the visual tree
                ItemsPanelRoot.SetValue(DataContextProperty, DataContext, DependencyPropertyValuePrecedences.Inheritance);
                OnApplyTemplatePartial();

                if (ScrollViewer?.Style?.Precedence == DependencyPropertyValuePrecedences.ImplicitStyle)
                {
                    throw new InvalidOperationException($"Performance hit: {this} is using a ScrollViewer in its template with a default style, which would break virtualization. A Style containing {nameof(ListViewBaseScrollContentPresenter)} must be used.");
                }

                if (ScrollViewer != null)
                {
                    NativePanel.HorizontalScrollBarVisibility = ScrollViewer.HorizontalScrollBarVisibility;
                    NativePanel.VerticalScrollBarVisibility   = ScrollViewer.VerticalScrollBarVisibility;
                }
            }
            else
            {
                if (ScrollViewer?.Style == Uno.UI.GlobalStaticResources.ListViewBaseScrollViewerStyle)
                {
                    // We're not using NativeListViewBase so we need a 'real' ScrollViewer
                    ScrollViewer.Style = Uno.UI.GlobalStaticResources.DefaultScrollViewerStyle;
                }
            }
        }
Beispiel #2
0
        partial void OnApplyTemplatePartial()
        {
            // NativePanel may not exist if we're using a non-virtualizing ItemsPanel.
            if (NativePanel != null)
            {
                // Propagate the DataContext manually, since ItemsPanelRoot isn't really part of the visual tree
                ItemsPanelRoot.SetValue(DataContextProperty, DataContext, DependencyPropertyValuePrecedences.Inheritance);

                if (ScrollViewer?.Style == null)
                {
                    throw new InvalidOperationException($"Performance hit: {this} is using a ScrollViewer in its template with a default style, which would break virtualization. A Style containing {nameof(ListViewBaseScrollContentPresenter)} must be used.");
                }

                if (ScrollViewer != null)
                {
                    NativePanel.HorizontalScrollBarVisibility = ScrollViewer.HorizontalScrollBarVisibility;
                    NativePanel.VerticalScrollBarVisibility   = ScrollViewer.VerticalScrollBarVisibility;
                }
            }
            else
            {
                if (ScrollViewer?.Style != null && ScrollViewer.Style == ResourceResolver.GetSystemResource <Style>("ListViewBaseScrollViewerStyle"))                //TODO: this, too, properly
                {
                    // We're not using NativeListViewBase so we need a 'real' ScrollViewer, remove the internal custom style
                    ScrollViewer.Style = null;
                }
            }
        }
Beispiel #3
0
        internal protected override void OnDataContextChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnDataContextChanged(e);

            // Propagate the DataContext manually, since ItemsPanelRoot isn't really part of the visual tree
            ItemsPanelRoot?.SetValue(DataContextProperty, DataContext, DependencyPropertyValuePrecedences.Inheritance);

            OnDataContextChangedPartial();
        }
Beispiel #4
0
 /// <summary>
 /// Re-size the ListView's Panel when the SplitView is compact so the items
 /// will fit within the visible space and correctly display a keyboard focus rect.
 /// </summary>
 private void OnPaneToggled()
 {
     if (splitView.IsPaneOpen)
     {
         ItemsPanelRoot.ClearValue(WidthProperty);
         ItemsPanelRoot.ClearValue(HorizontalAlignmentProperty);
     }
     else if (splitView.DisplayMode == SplitViewDisplayMode.CompactInline || splitView.DisplayMode == SplitViewDisplayMode.CompactOverlay)
     {
         ItemsPanelRoot.SetValue(WidthProperty, splitView.CompactPaneLength);
         ItemsPanelRoot.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Left);
     }
 }
 /// <summary>
 /// Re-size the ListView's Panel when the SplitView is compact so the items
 /// will fit within the visible space and correctly display a keyboard focus rect.
 /// </summary>
 private void OnPaneToggled()
 {
     if (_splitViewHost.IsPaneOpen)
     {
         ItemsPanelRoot.ClearValue(FrameworkElement.WidthProperty);
         ItemsPanelRoot.ClearValue(FrameworkElement.HorizontalAlignmentProperty);
     }
     else if (this._splitViewHost.DisplayMode == SplitViewDisplayMode.CompactInline ||
              this._splitViewHost.DisplayMode == SplitViewDisplayMode.CompactOverlay)
     {
         ItemsPanelRoot.SetValue(FrameworkElement.WidthProperty, this._splitViewHost.CompactPaneLength);
         ItemsPanelRoot.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
     }
 }
Beispiel #6
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            if (IsAutoSize)
            {
                if (item != null && this.Items != null && this.Items.IndexOf(item) == 0)
                {
                    if (ItemsPanelRoot != null)
                    {
                        ItemsPanelRoot.SetBinding(ItemsWrapGrid.ItemWidthProperty, new Binding()
                        {
                            Path = new PropertyPath("ItemWidth"), Source = this
                        });
                        ItemsPanelRoot.SetBinding(ItemsWrapGrid.ItemHeightProperty, new Binding()
                        {
                            Path = new PropertyPath("ItemHeight"), Source = this
                        });
                    }

                    OnUpdate();
                }

                var frameworkElement = element as FrameworkElement;
                if (frameworkElement != null)
                {
                    if (isUseItemMargin)
                    {
                        frameworkElement.Margin = _itemMargin;
                    }
                    else
                    {
                        frameworkElement.Margin = new Thickness(0, 0, HorizonMargin, VerticalMargin);
                    }
                }
            }

            base.PrepareContainerForItemOverride(element, item);
        }