Пример #1
0
        //protected override void ClearContainerForItemOverride(DependencyObject element, object item)
        //{
        //    if (!PlatformIndependent.IsWindowsPhoneDevice && ItemsSource != null && ItemsSource is IResizeableItems)
        //    {
        //        var gridview = (element as ListViewItem).ContentTemplateRoot as VariableSizedGridView;
        //        gridview.ItemClick -= Gridview_ItemClick;
        //        //variableSizedGridViews.Remove(gridview);
        //    }

        //    base.ClearContainerForItemOverride(element, item);
        //}

        private void GridviewItem_Loaded(object sender, RoutedEventArgs e)
        {
            var gridview = (sender as ListViewItem).ContentTemplateRoot as VariableSizedGridView;

            var resizeableItem = ResizeableItems.GetItem(this.ActualWidth);

            if (resizeableItem != null)
            {
                resizeableItem.ItemWidth = (int)(this.ActualWidth / resizeableItem.Columns - 7);
                gridview.ResizeableItem  = resizeableItem;
            }
            gridview.ItemClick -= Gridview_ItemClick;
            gridview.ItemClick += Gridview_ItemClick;
            //gridview.ItemTemplate = VirtualizedVariableSizedGridViewItemTemplate;
            Binding binding = new Binding();

            binding.Source = this;
            binding.Mode   = BindingMode.OneWay;
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            binding.Path = new PropertyPath("VirtualizedVariableSizedGridViewItemTemplate");
            gridview.SetBinding(GridView.ItemTemplateProperty, binding);

            Binding binding1 = new Binding();

            binding1.Source = this;
            binding1.Mode   = BindingMode.OneWay;
            binding1.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            binding1.Path = new PropertyPath("VirtualizedVariableSizedInternalGridViewContainerStyle");
            gridview.SetBinding(GridView.ItemContainerStyleProperty, binding1);
            (sender as ListViewItem).Loaded -= GridviewItem_Loaded;
        }
Пример #2
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            if (!PlatformIndependent.IsWindowsPhoneDevice && ItemsSource != null && ItemsSource is IResizeableItems)
            {
                base.ItemClick -= VirtualizedVariableSizedGridView_ItemClick;
                var gridviewItem = element as ListViewItem;
                if (VirtualizedVariableSizedGridViewItemContainerStyle != null)
                {
                    gridviewItem.Style = VirtualizedVariableSizedGridViewItemContainerStyle;
                }
                //Container Recycling, so ContentTemplateRoot maybe not null.
                if (gridviewItem.ContentTemplateRoot != null)
                {
                    var gridview = gridviewItem.ContentTemplateRoot as VariableSizedGridView;
                    //variableSizedGridViews.Add(gridview);
                    var resizeableItem = ResizeableItems.GetItem(this.ActualWidth);
                    if (resizeableItem != null)
                    {
                        resizeableItem.ItemWidth = (int)(this.ActualWidth / resizeableItem.Columns - 7);
                        gridview.ResizeableItem  = resizeableItem;
                        gridview.ItemClick      -= Gridview_ItemClick;
                        gridview.ItemClick      += Gridview_ItemClick;
                    }

                    if (gridview.ItemContainerStyle == null)
                    {
                        Binding binding1 = new Binding();
                        binding1.Source = this;
                        binding1.Mode   = BindingMode.OneWay;
                        binding1.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                        binding1.Path = new PropertyPath("VirtualizedVariableSizedInternalGridViewContainerStyle");
                        gridview.SetBinding(GridView.ItemContainerStyleProperty, binding1);
                    }
                }
                else
                {
                    gridviewItem.Loaded -= GridviewItem_Loaded;
                    gridviewItem.Loaded += GridviewItem_Loaded;
                }
            }
        }
Пример #3
0
        private void OnMeasureOverride(Size availableSize)
        {
            if (ItemsSource != null && ItemsSource is IResizeableItems && availableSize != Size.Empty)
            {
                var resizeableItem = ResizeableItems.GetItem(availableSize.Width);

                if (resizeableItem != null)
                {
                    resizeableItem.ItemWidth = (int)(availableSize.Width / resizeableItem.Columns - 7);

                    foreach (var item in this.Items)
                    {
                        var gridviewItem = this.ContainerFromItem(item) as ListViewItem;
                        //not null, it's in viewport, so it need to update.
                        if (gridviewItem != null && gridviewItem.ContentTemplateRoot != null)
                        {
                            var gridview = gridviewItem.ContentTemplateRoot as VariableSizedGridView;
                            gridview.ResizeableItem = null;
                            gridview.ResizeableItem = resizeableItem;
                        }
                    }
                }
            }
        }
Пример #4
0
        private void InitializeResizeableItems()
        {
            if (_resizeableItems == null)
            {
                _resizeableItems = new ResizeableItems();

                //ApplicationView.GetForCurrentView().SetPreferredMinSize(new Windows.Foundation.Size(200, 200));

                double windowMinwidth = 500;
                double windowMaxwidth = DeviceInfo.DeviceScreenSize.Width;
                double rangwidth      = (windowMaxwidth - windowMinwidth) / 4.0;

                #region 4
                var list = new List <Resizable>();
                list.Add(new Resizable()
                {
                    Width = 2, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });

                var c4 = new ResizeableItem()
                {
                    Columns = 4, Items = list, Min = windowMinwidth + rangwidth * 3 + 1, Max = double.PositiveInfinity
                };
                _resizeableItems.Add(c4);
                #endregion

                #region 3
                list = new List <Resizable>();
                list.Add(new Resizable()
                {
                    Width = 2, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });

                var c3 = new ResizeableItem()
                {
                    Columns = 3, Items = list, Min = windowMinwidth + rangwidth * 2 + 1, Max = windowMinwidth + rangwidth * 3
                };
                _resizeableItems.Add(c3);
                #endregion

                #region 2
                list = new List <Resizable>();
                list.Add(new Resizable()
                {
                    Width = 2, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 2
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 1, Height = 1
                });

                var c2 = new ResizeableItem()
                {
                    Columns = 2, Items = list, Min = windowMinwidth + rangwidth * 1 + 1, Max = windowMinwidth + rangwidth * 2
                };
                _resizeableItems.Add(c2);
                #endregion

                #region 1
                list = new List <Resizable>();
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });
                list.Add(new Resizable()
                {
                    Width = 2, Height = 1
                });

                var c1 = new ResizeableItem()
                {
                    Columns = 2, Items = list, Min = windowMinwidth + +1, Max = windowMinwidth + rangwidth * 1
                };
                _resizeableItems.Add(c1);
                #endregion
            }
        }