private void RefreshItems() { if (boxContianer == null) { return; } BindListener(); var data = Items?.ToList(); var count = data == null ? 0 : data.Count(); var j = 0; var removeItems = new List <int>(); for (int i = 0; i < boxContianer.Children.Count; i++) { var item = boxContianer.Children[i]; if (item is AddListBoxItem) { continue; } if (j >= count) { removeItems.Add(i); j++; continue; } (item as BookListBoxItem).Source = data[j]; j++; } if (removeItems.Count > 0) { for (int i = removeItems.Count - 1; i >= 0; i--) { boxContianer.Children.RemoveAt(removeItems[i]); } } if (j >= count) { MoveActionButton(); return; } for (; j < count; j++) { var book = new BookListBoxItem(); book.Width = ItemWidth; book.Height = ItemHeight; book.OnAction += (_, item, e) => { if (e == ActionEvent.NONE) { boxMenu?.Show(GetActionPosition(book)); return; } OnAction?.Invoke(this, item, e); }; boxContianer.Children.Add(book); book.Source = data[j]; } MoveActionButton(); RefreshSize(); }
private Point GetActionPosition(BookListBoxItem item) { var p = item.TransformToVisual(this).TransformPoint(new Point(0, 0)); p.X += item.ActualWidth - 60; p.Y += 30; return(p); }