private void ItemsWrapGrid_Loaded(object sender, RoutedEventArgs e) { if (_itemsWrapGrid == null) { _itemsWrapGrid = sender as ItemsWrapGrid; } }
private async void ItemsWrapGrid_SizeChanged(object sender, SizeChangedEventArgs e) { await RunOnUIThreadAsync(CoreDispatcherPriority.Low, () => { ItemsWrapGrid grid = (ItemsWrapGrid)sender; // set number of columns and apply correct sizing to items if (e.NewSize.Width > 350) { grid.MaximumRowsOrColumns = 4; if (grid.ActualWidth == 0) { return; } double size = grid.ActualWidth / 4; grid.ItemWidth = grid.ItemHeight = size; } else { grid.MaximumRowsOrColumns = 2; if (grid.ActualWidth == 0) { return; } double size = grid.ActualWidth / 2; grid.ItemWidth = grid.ItemHeight = size; } }); }
//page resize private void OptimizeLook(object sender, SizeChangedEventArgs e) { ItemsWrapGrid appItemsPanel = (ItemsWrapGrid)NewsList.ItemsPanelRoot; if (appItemsPanel != null) { double screenWidth = Window.Current.Bounds.Width; //privremeno... if (screenWidth >= 1500) { appItemsPanel.ItemWidth = screenWidth / 4 - 30; } else if (screenWidth >= 1100) { appItemsPanel.ItemWidth = screenWidth / 3 - 40; } else if (screenWidth >= 700) { appItemsPanel.ItemWidth = screenWidth / 2 - 80; } else { appItemsPanel.ItemWidth = screenWidth - 60; } //double moduo300 = Math.Round((screenWidth - 700) / 300); //appItemsPanel.ItemWidth = (screenWidth / (moduo300 + 2)) - (60 - 10 * moduo300); } }
private void OnViewChanged(object sender, ScrollViewerViewChangedEventArgs e) { if (sender is ScrollViewer scrollingHost) { ViewModel.VerticalOffset = scrollingHost.VerticalOffset; if (DateHeaderLabel == null) { return; } var index = ScrollingHost.ItemsPanelRoot switch { ItemsStackPanel stackPanel => stackPanel.FirstVisibleIndex, ItemsWrapGrid wrapGrid => wrapGrid.FirstVisibleIndex, _ => - 1 }; var container = ScrollingHost.ContainerFromIndex(index) as SelectorItem; if (container == null || container.Tag is not Message message) { return; } DateHeaderLabel.Text = Converter.MonthGrouping(Utils.UnixTimestampToDateTime(message.Date)); _dateHeaderTimer.Stop(); _dateHeaderTimer.Start(); ShowHideDateHeader(scrollingHost.VerticalOffset > ProfileHeader.ActualHeight, true); } }
private void Image_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { Image senderImg = sender as Image; senderImg.Blur(value: 0, duration: 100, delay: 0).StartAsync(); //senderImg.Scale(centerX: 50.0f, centerY: 50.0f, scaleX: 3.0f, scaleY: 3.0f, duration: 100, delay: 0).StartAsync(); Grid itemGrid = VisualTreeHelper.GetParent(senderImg) as Grid; ListViewItemPresenter lvip = VisualTreeHelper.GetParent(itemGrid) as ListViewItemPresenter; GridViewItem gvi = VisualTreeHelper.GetParent(lvip) as GridViewItem; ItemsWrapGrid grid = VisualTreeHelper.GetParent(gvi) as ItemsWrapGrid; string senderAutomationId = AutomationProperties.GetAutomationId(senderImg); foreach (GridViewItem item in grid.Children) { ListViewItemPresenter lviPresenter = VisualTreeHelper.GetChild(item, 0) as ListViewItemPresenter; Grid imageGrid = VisualTreeHelper.GetChild(lviPresenter, 0) as Grid; Image image = VisualTreeHelper.GetChild(imageGrid, 0) as Image; string imageAutomationId = AutomationProperties.GetAutomationId(image); if (imageAutomationId != senderAutomationId) { image.Blur(value: 2.5, duration: 300, delay: 0).StartAsync(); //image.Scale(centerX: 0.0f, centerY: 0.0f, scaleX: 1.0f, scaleY: 1.0f, duration: 100, delay: 0).StartAsync(); } } }
private void Page_Loaded(object sender, RoutedEventArgs e) { ItemsWrapGrid itemsWrapGrid = GameBoardGrid.ItemsPanelRoot as ItemsWrapGrid; itemsWrapGrid.MaximumRowsOrColumns = Board.BoardSize; DataContext = Board; TurnOffGridViewClipping(); Board.LoadButtonsList(GameBoardGrid); Board.Reset(); var boardVisual = ElementCompositionPreview.GetElementVisual(GameBoardGrid); boardVisual.BorderMode = CompositionBorderMode.Soft; var controls = (GameBoardGrid.ItemsPanelRoot as ItemsWrapGrid).Children; foreach (FrameworkElement b in controls) { var newButtonVisual = ElementCompositionPreview.GetElementVisual(b); } _solidTileForegroundBrush = (SolidColorBrush)this.Resources["TileForeground"]; _solidTileBrush = (SolidColorBrush)this.Resources["TileBackground"]; GazeInput.DwellFeedbackProgressBrush = _solidTileForegroundBrush; GazeInput.DwellFeedbackCompleteBrush = new SolidColorBrush(Colors.Transparent); }
private void GridViewEx_Loaded(object sender, RoutedEventArgs e) { // 为了响应式 _itemsWrapGrid = this.GetFirstDescendantOfType <ItemsWrapGrid>(); _itemsWrapGrid.ItemHeight = this.ItemHeight; int c = (int)Math.Floor(this.ActualWidth / this.ItemWidthSuggest); _itemsWrapGrid.ItemWidth = this.ActualWidth / c; if (c > 1) { this.ItemContainerStyle = (this.GetTemplateChild("RootLayout") as Grid).Resources["GridViewItemStyle2"] as Style; } else { this.ItemContainerStyle = (this.GetTemplateChild("RootLayout") as Grid).Resources["GridViewItemStyle1"] as Style; } // to advoid crash in xaml designer if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled) { _refreshIconVisual.CenterPoint = new Vector3(Convert.ToSingle(_refreshIcon.Width / 2), Convert.ToSingle(_refreshIcon.Height / 2), 0); } //this.SizeChanged += (s, ee) => //{ // int colum = (int)Math.Floor(ee.NewSize.Width / this.ItemWidthSuggest); // _itemsWrapGrid.ItemWidth = ee.NewSize.Width / colum; //}; }
internal void SaveState(Dictionary <string, object> pageState) { if (Root.ItemsPanelRoot == null) { return; } ItemsStackPanel stackPanel = Root.ItemsPanelRoot as ItemsStackPanel; if (stackPanel != null) { pageState.Add(LAST_INDEX_KEY, stackPanel.LastVisibleIndex); } else { ItemsWrapGrid wrapGrid = Root.ItemsPanelRoot as ItemsWrapGrid; if (wrapGrid != null) { pageState.Add(LAST_INDEX_KEY, wrapGrid.LastVisibleIndex); } else { DebugHelper.Alert(new CallerInfo(), "Unexpected root type: {0}", Root.ItemsPanelRoot.GetType()); } } }
private void Grid_SizeChanged(object sender, SizeChangedEventArgs e) { double w = GRIDroot.ActualWidth; w -= 20; ItemsWrapGrid wrap = GetItemsWrapGrid(GRIDVWcode); try { if (w < 650) { wrap.ItemWidth = w; } else if (w < 850) { wrap.ItemWidth = w; } else if (w < 1150) { wrap.ItemWidth = w / 2; } else if (w < 1600) { wrap.ItemWidth = w / 2; } else { wrap.ItemWidth = w / 5; } } catch { } }
private void GRIDLFRoot_SizeChanged(object sender, SizeChangedEventArgs e) { double w = GRIDLFRoot.ActualWidth; w -= 20; ItemsWrapGrid wrap = Util.GetItemsWrapGrid(GRDVWLF); try { if (w < 650) { wrap.ItemWidth = w; } else if (w < 850) { wrap.ItemWidth = w / 2; } else if (w < 1150) { wrap.ItemWidth = w / 3; } else if (w < 1600) { wrap.ItemWidth = w / 4; } else { wrap.ItemWidth = w / 5; } } catch { } }
private void StyledGrid_InitWrapGrid(object sender, RoutedEventArgs e) { // Update ItemsWrapGrid object created on page load by assigning it to StyledGrid's ItemWrapGrid StyledGridIWG = sender as ItemsWrapGrid; // Now we can change StyledGrid's MaximumRowsorColumns property within its ItemsPanel>ItemsPanelTemplate>ItemsWrapGrid. StyledGridIWG.MaximumRowsOrColumns = ActualMaxItems; }
public void Attach(DependencyObject associatedObject) { _target = (ItemsWrapGrid)associatedObject; _target.SizeChanged += TargetOnSizeChanged; AssociatedObject = associatedObject; }
private void ItemsWrapGrid_SizeChanged(object sender, SizeChangedEventArgs e) { ItemsWrapGrid itemsWrapGrid = sender as ItemsWrapGrid; if (itemsWrapGrid != null) { itemsWrapGrid.ItemWidth = e.NewSize.Width / Columns; } }
private static async void InternalModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AdaptiveCollectionView obj = (AdaptiveCollectionView)d; AdaptiveCollectionViewMode value = (AdaptiveCollectionViewMode)e.NewValue; if (Enum.IsDefined(typeof(AdaptiveCollectionViewMode), value) == false) { throw new ArgumentException($"{nameof(AdaptiveCollectionViewMode)} is not defined", nameof(value)); } int index = -1; if (obj.Items.Count > 0) { ItemsStackPanel stackPanel = obj.ItemsPanelRoot as ItemsStackPanel; if (stackPanel != null) { index = stackPanel.FirstVisibleIndex; } ItemsWrapGrid wrapGrid = obj.ItemsPanelRoot as ItemsWrapGrid; if (wrapGrid != null) { index = wrapGrid.FirstVisibleIndex; } } if (value == AdaptiveCollectionViewMode.List) { obj.ItemsPanel = obj._itemsStackPanel; } else { obj.ItemsPanel = obj._itemsWrapGrid; } if (obj.ModeChanged != null) { obj.ModeChanged(obj, new AdaptiveCollectionViewModeChangedEventArgs((AdaptiveCollectionViewMode)e.OldValue, (AdaptiveCollectionViewMode)e.NewValue)); } await obj.WaitForLayoutUpdatedAsync(); if (obj.SelectedItem != null) { obj.ScrollIntoView(obj.SelectedItem, ScrollIntoViewAlignment.Leading); } else if (index > -1) { var item = obj.Items.ElementAtOrDefault(index); if (item != null) { obj.ScrollIntoView(item, ScrollIntoViewAlignment.Leading); } } }
private void SpacesGridView_SizeChanged(object sender, SizeChangedEventArgs e) { try { ItemsWrapGrid appItemsPanel = (ItemsWrapGrid)SpacesGridView.ItemsPanelRoot; appItemsPanel.ItemWidth = (e.NewSize.Width) / ((int)e.NewSize.Width / 200); } catch { Debug.WriteLine("GridViewItem Size could not be changed"); } }
private static void UpdateItemSize(ItemsWrapGrid itemsWrapGrid) { var availableWidth = Window.Current.Bounds.Width; var maxItemSize = GetMaxItemSize(itemsWrapGrid); var horizontalItems = Math.Ceiling(availableWidth / maxItemSize); var itemSize = Math.Floor(availableWidth / horizontalItems); itemsWrapGrid.ItemWidth = itemSize; itemsWrapGrid.ItemHeight = itemSize; }
private static void OnDesiredItemWidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ItemsWrapGrid @this = (ItemsWrapGrid)d; // Only add the handler the first time if (!ControlsMap.TryGetValue(@this, out _)) { ControlsMap.Add(@this, null); @this.SizeChanged += ItemsWrapGrid_SizeChanged; } }
private void Newsfeed_SizeChanged(object sender, SizeChangedEventArgs e) { ItemsWrapGrid MyItemsPanel = (ItemsWrapGrid)Newsfeed.ItemsPanelRoot; var width = e.NewSize.Width / 2; MyItemsPanel.ItemWidth = width; Messenger.Default.Send(new WidthMessage() { Width = width }); }
private void OnGridViewSizeChanged(object sender, SizeChangedEventArgs e) { try { ItemsWrapGrid itemsPanel = (ItemsWrapGrid)GrVDocuments.ItemsPanelRoot; double margin = 10.0; var itemNumberPerRow = 3; itemsPanel.ItemWidth = (e.NewSize.Width - margin * itemNumberPerRow) / (double)itemNumberPerRow; itemsPanel.ItemHeight = 110; } catch (Exception) { } }
void Responsive(ItemsWrapGrid grid) { if (grid == null) { return; } double width; width = DeviceHelper.IsPortrait() ? Window.Current.Bounds.Width : 400; grid.ItemWidth = (width - 48) / 4; grid.ItemHeight = grid.ItemWidth; }
//----------------------------------------------------------------------------- private void OnSizeChanged(object sender, SizeChangedEventArgs e) { GridView gridView = (GridView)sender; ItemsWrapGrid panel = ((ItemsWrapGrid)gridView.ItemsPanelRoot); const int minColWidth = 250; var columns = System.Math.Ceiling(ActualWidth / minColWidth); double newWidth = e.NewSize.Width / columns; panel.ItemWidth = newWidth; panel.ItemHeight = newWidth; }
public static void ComputeAlbums(ItemsWrapGrid wrapGrid, double? width = null, TemplateSize size = TemplateSize.Compact) { if (width == null) width = Window.Current.Bounds.Width; var splitScreen = (size == TemplateSize.Compact) ? 3 : 2; if (width > tileSize*splitScreen) { wrapGrid.ItemWidth = tileSize; wrapGrid.ItemHeight = tileSize + contentGridWindows; } else { wrapGrid.ItemWidth = (width.Value / splitScreen); wrapGrid.ItemHeight = wrapGrid.ItemWidth + contentGridWindows; } }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); // First populate our local variable for referencing ItemsWrapGrid for the first time. if (!_isFirstItemContainerLoaded && _virtualizedPanel == null) { _virtualizedPanel = ItemsPanelRoot as ItemsWrapGrid; } this.PrepareContainerForItemOverrideEx <GridViewItem>( element, () => (_virtualizedPanel.FirstVisibleIndex, _virtualizedPanel.LastVisibleIndex), ref _isFirstItemContainerLoaded); }
private void OnGridViewLoaded(object sender, RoutedEventArgs routedEventArgs) { if (this.gridViewPanel == null) { this.gridViewPanel = TreeHelper.FindVisualChild <ItemsWrapGrid>(this.gridviewTasks); if (this.gridViewPanel != null) { this.gridViewPanel.Drop += this.OnGridViewGroupDrop; this.gridViewPanel.DragOver += this.OnGridViewDragOver; this.gridViewPanel.DragLeave += this.OnGridViewDragLeave; this.dragDropHost = TreeHelper.FindVisualChildren <Border>(this.gridviewTasks).FirstOrDefault(c => c.Name == "dragDropFeedbackHost"); this.dragDropHost.DragOver += this.OnGridViewDragOver; } } }
private void ItemsWrapGridDemo_Loaded(object sender, RoutedEventArgs e) { DispatcherTimer dTimer = new DispatcherTimer(); dTimer.Interval = TimeSpan.Zero; dTimer.Tick += DTimer_Tick; dTimer.Start(); // 获取 GridView 中的 ItemsWrapGrid 控件 _itemsWrapGrid1 = gridView1.ItemsPanelRoot as ItemsWrapGrid; _itemsWrapGrid2 = gridView2.ItemsPanelRoot as ItemsWrapGrid; // 获取 GridView 中的 ItemsWrapGrid 控件 // _itemsWrapGrid1 = Helper.GetVisualChild<ItemsWrapGrid>(gridView1); // _itemsWrapGrid2 = Helper.GetVisualChild<ItemsWrapGrid>(gridView2); }
public static void ComputeAlbumTracks(ref ItemsWrapGrid wrapGrid, double?width = null) { if (width == null) { width = Window.Current.Bounds.Width; } if (width > 700) { wrapGrid.ItemWidth = width.Value / 2; } else { wrapGrid.ItemWidth = width.Value; } wrapGrid.ItemHeight = 35; }
public static void ComputeCompactVideo(ItemsWrapGrid wrapGrid, double? width = null) { if (width == null) width = Window.Current.Bounds.Width; const int splitScreen = 2; if (width > 600) { wrapGrid.ItemWidth = 307; wrapGrid.ItemHeight = tileSize + contentGridWindows; } else { var itemWidth = width.Value / splitScreen; var itemHeight = itemWidth * 0.5625 + contentGridWindows; wrapGrid.ItemHeight = itemHeight; wrapGrid.ItemWidth = itemWidth; } }
private static void ItemsWrapGrid_SizeChanged(object sender, SizeChangedEventArgs e) { ItemsWrapGrid @this = (ItemsWrapGrid)sender; double desiredWidth = GetDesiredItemWidth(@this), columns = Math.Ceiling(e.NewSize.Width / desiredWidth); int maximumRowsOrColumns = @this.MaximumRowsOrColumns; if (maximumRowsOrColumns > 0) { columns = Math.Min(columns, maximumRowsOrColumns); } @this.ItemWidth = e.NewSize.Width / columns; }
private void UpdateItemSize() { ItemsWrapGrid itemsWrapGrid = (ItemsWrapGrid)gridviewImages.ItemsPanelRoot; if (itemsWrapGrid != null) { double optimizedWidth = 200; double number = (int)itemsWrapGrid.ActualWidth / (int)optimizedWidth; double newSize = itemsWrapGrid.ActualWidth / number; if (itemsWrapGrid != null) { itemsWrapGrid.ItemWidth = (int)newSize; itemsWrapGrid.ItemHeight = (int)newSize * 0.6; } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void listView_SizeChanged(object sender, SizeChangedEventArgs e) { //Unbox the sender. var itemsControl = sender as ListViewBase; //Retrieve items panel. ItemsWrapGrid itemsPanel = itemsControl.ItemsPanelRoot as ItemsWrapGrid; //If the items panel is a wrap grid. if (itemsPanel != null) { //Get total size (leave room for scrolling.) var total = e.NewSize.Width - 10; //Minimum item size. var itemMinSize = (double)itemsControl.GetValue(MinItemWidthProperty); //How many items can be fit whole. var canBeFit = Math.Floor(total / itemMinSize); //I could add logic that if the total items //are less then the number of items that //would fit then devide the total size by //the number of items rather than the number //of items that would actually fit. if ((bool)itemsControl.GetValue(FillBeforeWrapProperty) && itemsControl.Items.Count > 0 && itemsControl.Items.Count < canBeFit) { canBeFit = itemsControl.Items.Count; } //Set the items Panel item width appropriately. //Note you will need your container to stretch //along with the items panel or it will look //strange. // <GridView.ItemContainerStyle> //< Style TargetType = "GridViewItem" > //< Setter Property = "HorizontalContentAlignment" Value = "Stretch" /> // < Setter Property = "HorizontalAlignment" Value = "Stretch" /> //</ Style > // </ GridView.ItemContainerStyle > itemsPanel.ItemWidth = total / canBeFit; } }
private async void OnLoaded(object sender, RoutedEventArgs e) { var panel = ItemsPanelRoot as ItemsWrapGrid; if (panel != null) { ItemsStack = panel; ItemsStack.SizeChanged += Panel_SizeChanged; } if (IncrementalSource != null && IncrementalSource.HasMoreItems && !_isAlreadyLoading) { _isAlreadyLoading = true; await IncrementalSource.LoadMoreItemsAsync(0); _isAlreadyLoading = false; } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); //If the property is width. if (e.PropertyName == "Width" || e.PropertyName == "Padding") { //Unbox the xamarin host control. var list = sender as Xamarin.Forms.ListView; //Get the Minimum item size. var itemMinSize = (double)list.GetValue(JWChinese.GridView.MinItemWidthProperty); var padding = (double)list.GetValue(JWChinese.GridView.PaddingProperty); //If the property is set. if (itemMinSize > 0) { //Unbox the native control. var itemsControl = Control as ListViewBase; //Retrieve items panel. ItemsWrapGrid itemsPanel = itemsControl.ItemsPanelRoot as ItemsWrapGrid; //If the items panel is a wrap grid. if (itemsPanel != null) { //Get total size (leave room for scrolling.) SUBTRACT 10 IF INCLUDING SCROLLER var total = list.Width - (padding * 2); //How many items can be fit whole. var canBeFit = Math.Floor(total / itemMinSize); //Set the items Panel item width appropriately. //Note you will need your container to stretch //along with the items panel or it will look //strange. itemsPanel.ItemWidth = total / canBeFit; itemsControl.Padding = new Windows.UI.Xaml.Thickness(padding, 0, padding, padding); } } } }
public static void ComputeAlbums(ItemsWrapGrid wrapGrid, double?width = null, TemplateSize size = TemplateSize.Compact) { if (width == null) { width = Window.Current.Bounds.Width; } var splitScreen = (size == TemplateSize.Compact) ? 3 : 2; if (width > tileSize * splitScreen) { wrapGrid.ItemWidth = tileSize; wrapGrid.ItemHeight = tileSize + contentGridWindows; } else { wrapGrid.ItemWidth = (width.Value / splitScreen); wrapGrid.ItemHeight = wrapGrid.ItemWidth + contentGridWindows; } }
public void Detach() { _target = null; }
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e) { _itemsWrapGrid = sender as ItemsWrapGrid; }
private void VariableSizedWrapGrid_Loaded(object sender, RoutedEventArgs e) { _wrapGrid = sender as ItemsWrapGrid; SetItemsWidth(); }