示例#1
0
        public PropertyItemsControl()
        {
#if !NET40
            VirtualizingPanel.SetIsVirtualizingWhenGrouping(this, true);
            VirtualizingPanel.SetScrollUnit(this, ScrollUnit.Pixel);
#endif
        }
        private void CustomListView_Loaded(object sender, RoutedEventArgs e)
        {
            _scrollViewer = VisualSearchHelper.GetChildObject <ScrollViewer>(this, string.Empty);
            ScrollViewer.SetHorizontalScrollBarVisibility(this, ScrollBarVisibility.Disabled);
            ScrollViewer.SetCanContentScroll(this, true);
            VirtualizingPanel.SetIsVirtualizing(this, true);
            //设置ScrollUnit
            ScrollUnit scrollUnit;

            switch (CustomSlidingMode)
            {
            case SlidingModeType.Pixel:
                scrollUnit = ScrollUnit.Pixel;
                break;

            case SlidingModeType.Row:
                scrollUnit = ScrollUnit.Item;
                break;

            default:
                scrollUnit = ScrollUnit.Pixel;
                break;
            }
            VirtualizingPanel.SetScrollUnit(this, scrollUnit);
        }
示例#3
0
        protected override void OnElementChanged(ElementChangedEventArgs <ListView> e)
        {
            if (e.OldElement != null)             // Clear old element event
            {
                e.OldElement.ItemSelected      -= OnElementItemSelected;
                e.OldElement.ScrollToRequested -= OnElementScrollToRequested;

                var templatedItems = ((ITemplatedItemsView <Cell>)e.OldElement).TemplatedItems;
                templatedItems.CollectionChanged        -= OnCollectionChanged;
                templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
            }

            if (e.NewElement != null)
            {
                e.NewElement.ItemSelected      += OnElementItemSelected;
                e.NewElement.ScrollToRequested += OnElementScrollToRequested;

                if (Control == null)                 // Construct and SetNativeControl and suscribe control event
                {
                    var listView = new WList
                    {
                        DataContext  = Element,
                        ItemTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["CellTemplate"],
                        Style        = (System.Windows.Style)System.Windows.Application.Current.Resources["ListViewTemplate"]
                    };

                    VirtualizingPanel.SetVirtualizationMode(listView, VirtualizationMode.Recycling);
                    VirtualizingPanel.SetScrollUnit(listView, ScrollUnit.Pixel);
                    SetNativeControl(listView);

                    Control.MouseUp  += OnNativeMouseUp;
                    Control.KeyUp    += OnNativeKeyUp;
                    Control.TouchUp  += OnNativeTouchUp;
                    Control.StylusUp += OnNativeStylusUp;
                }

                // Suscribe element events
                var templatedItems = TemplatedItemsView.TemplatedItems;
                templatedItems.CollectionChanged        += OnCollectionChanged;
                templatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged;

                // Update control properties
                UpdateItemSource();
                UpdateHorizontalScrollBarVisibility();
                UpdateVerticalScrollBarVisibility();

                if (Element.SelectedItem != null)
                {
                    OnElementItemSelected(null, new SelectedItemChangedEventArgs(Element.SelectedItem, -1));
                }
            }

            base.OnElementChanged(e);
        }
示例#4
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            ControlGameView = Template.FindName("PART_ControlGameView", this) as Control;
            if (ControlGameView != null)
            {
                BindingTools.SetBinding(ControlGameView,
                                        Control.DataContextProperty,
                                        mainModel,
                                        nameof(DesktopAppViewModel.SelectedGameDetails));
            }

            ListGames = Template.FindName("PART_ListGames", this) as ExtendedListBox;
            if (ListGames != null)
            {
                SetListGamesBinding();
                BindingTools.SetBinding(ListGames,
                                        ExtendedListBox.SelectedItemProperty,
                                        mainModel,
                                        nameof(DesktopAppViewModel.SelectedGame),
                                        BindingMode.TwoWay);
                BindingTools.SetBinding(ListGames,
                                        ExtendedListBox.SelectedItemsListProperty,
                                        mainModel,
                                        nameof(DesktopAppViewModel.SelectedGamesBinder),
                                        BindingMode.TwoWay);

                ScrollToSelectedBehavior.SetEnabled(ListGames, true);

                if (!DesignerProperties.GetIsInDesignMode(this))
                {
                    ListGames.InputBindings.Add(new KeyBinding(mainModel.EditSelectedGamesCommand, mainModel.EditSelectedGamesCommand.Gesture));
                    ListGames.InputBindings.Add(new KeyBinding(mainModel.RemoveSelectedGamesCommand, mainModel.RemoveSelectedGamesCommand.Gesture));
                    ListGames.InputBindings.Add(new KeyBinding(mainModel.StartSelectedGameCommand, mainModel.StartSelectedGameCommand.Gesture));
                }

                ListGames.SelectionMode = SelectionMode.Extended;
                VirtualizingPanel.SetCacheLengthUnit(ListGames, VirtualizationCacheLengthUnit.Item);
                VirtualizingPanel.SetCacheLength(ListGames, new VirtualizationCacheLength(5));
                VirtualizingPanel.SetScrollUnit(ListGames, ScrollUnit.Pixel);
                VirtualizingPanel.SetIsVirtualizingWhenGrouping(ListGames, true);
                VirtualizingPanel.SetVirtualizationMode(ListGames, VirtualizationMode.Recycling);
            }

            ControlTemplateTools.InitializePluginControls(
                mainModel.Extensions,
                Template,
                this,
                SDK.ApplicationMode.Desktop,
                mainModel,
                $"{nameof(DesktopAppViewModel.SelectedGameDetails)}.{nameof(GameDetailsViewModel.Game)}.{nameof(GameDetailsViewModel.Game.Game)}");
        }
示例#5
0
        protected override void OnElementChanged(ElementChangedEventArgs <ListView> e)
        {
            if (e.OldElement != null)             // Clear old element event
            {
                e.OldElement.ItemSelected      -= OnElementItemSelected;
                e.OldElement.ScrollToRequested -= OnElementScrollToRequested;

                var templatedItems = ((ITemplatedItemsView <Cell>)e.OldElement).TemplatedItems;
                templatedItems.CollectionChanged        -= OnCollectionChanged;
                templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
                if (_listview != null)
                {
                    _listview.MouseUp  -= OnNativeMouseUp;
                    _listview.KeyUp    -= OnNativeKeyUp;
                    _listview.TouchUp  -= OnNativeTouchUp;
                    _listview.StylusUp -= OnNativeStylusUp;
                    _listview.Loaded   -= ControlOnLoaded;
                }

                if (_scrollViewer != null)
                {
                    _scrollViewer.ScrollChanged -= SendScrolled;
                }

                if (Control is object)
                {
                    Control.SizeChanged -= Grid_SizeChanged;
                }
            }

            if (e.NewElement != null)
            {
                e.NewElement.ItemSelected      += OnElementItemSelected;
                e.NewElement.ScrollToRequested += OnElementScrollToRequested;

                if (_listview == null)                 // Construct and SetNativeControl and suscribe control event
                {
                    _listview = new WList
                    {
                        DataContext  = Element,
                        ItemTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["CellTemplate"],
                        Style        = (System.Windows.Style)System.Windows.Application.Current.Resources["ListViewTemplate"]
                    };

                    VirtualizingPanel.SetVirtualizationMode(_listview, VirtualizationMode.Recycling);
                    VirtualizingPanel.SetScrollUnit(_listview, ScrollUnit.Pixel);

                    SetNativeControl(_grid);

                    // Setup grid for header/listview/footer
                    Control.RowDefinitions.Add(new System.Windows.Controls.RowDefinition {
                        Height = System.Windows.GridLength.Auto
                    });
                    Control.RowDefinitions.Add(new System.Windows.Controls.RowDefinition {
                        Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star)
                    });
                    Control.RowDefinitions.Add(new System.Windows.Controls.RowDefinition {
                        Height = System.Windows.GridLength.Auto
                    });

                    WGrid.SetRow(_listview, 1);

                    Control.Children.Add(_listview);

                    _listview.MouseUp  += OnNativeMouseUp;
                    _listview.KeyUp    += OnNativeKeyUp;
                    _listview.TouchUp  += OnNativeTouchUp;
                    _listview.StylusUp += OnNativeStylusUp;
                    _listview.Loaded   += ControlOnLoaded;
                }

                // Subscribe element events
                var templatedItems = TemplatedItemsView.TemplatedItems;
                templatedItems.CollectionChanged        += OnCollectionChanged;
                templatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged;

                Control.SizeChanged += Grid_SizeChanged;

                // Update control properties
                UpdateHeader();
                UpdateFooter();
                UpdateItemSource();
                UpdateHorizontalScrollBarVisibility();
                UpdateVerticalScrollBarVisibility();

                if (Element.SelectedItem != null)
                {
                    OnElementItemSelected(null, new SelectedItemChangedEventArgs(Element.SelectedItem, -1));
                }
            }

            base.OnElementChanged(e);
        }