private void lstHome_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { }
public static void SetInterElementDelay(ListViewBase obj, double value) => obj.SetValue(InterElementDelayProperty, value);
public static void SetAnimateOnItemsSourceChange(ListViewBase obj, bool value) => obj.SetValue(AnimateOnItemsSourceChangeProperty, value);
public static void SetItemsBinding(ListViewBase obj, bool value) => obj.SetValue(ItemsBindingProperty, value);
public static void SetItems(ListViewBase obj, AnimationSettings value) => obj.SetValue(ItemsProperty, value);
public static void SetColor(ListViewBase obj, Brush value) { obj.SetValue(ColorProperty, value); }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue == true) { // XAML has indicated that the item is no longer being shown, so add it to the recycle queue var tag = args.ItemContainer.Tag as string; #if ENABLE_DEBUG_SPEW Debug.WriteLine($"Adding {args.ItemContainer.GetHashCode()} to {tag}"); #endif // ENABLE_DEBUG_SPEW var added = _typeToItemHashSetMapping[tag].Add(args.ItemContainer); #if ENABLE_DEBUG_SPEW Debug.Assert(added == true, "Recycle queue should never have dupes. If so, we may be incorrectly reusing a container that is already in use!"); #endif // ENABLE_DEBUG_SPEW return; } var message = args.Item as MessageViewModel; var content = args.ItemContainer.ContentTemplateRoot as FrameworkElement; content.Tag = message; if (content is Grid grid) { var photo = grid.FindName("Photo") as ProfilePicture; if (photo != null) { photo.Tag = message; if (message.IsSaved()) { if (message.ForwardInfo is MessageForwardedFromUser fromUser) { var user = message.ProtoService.GetUser(fromUser.SenderUserId); if (user != null) { photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 32, 32); } } else if (message.ForwardInfo is MessageForwardedPost post) { var chat = message.ProtoService.GetChat(post.ForwardedFromChatId); if (chat != null) { photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 32, 32); } } } else { var user = message.GetSenderUser(); if (user != null) { photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 32, 32); } } } content = grid.FindName("Bubble") as FrameworkElement; } else if (content is StackPanel panel && !(content is MessageBubble)) { content = panel.FindName("Service") as FrameworkElement; } if (content is MessageBubble bubble) { bubble.UpdateMessage(args.Item as MessageViewModel); args.Handled = true; } else if (content is MessageService service) { service.UpdateMessage(args.Item as MessageViewModel); args.Handled = true; } }
public static void SetCommand(ListViewBase obj, ICommand value) { obj.SetValue(CommandProperty, value); }
public static object GetCommandParameter(ListViewBase obj) { return(obj.GetValue(CommandParameterProperty)); }
/// <summary> /// Event fired when we change ListView active assets order /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void ListViewActiveAssets_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args) { var assetsInListView = (sender as ListView).Items.OfType <Asset>().ToList(); await this.CurrentDevice.UpdateOrderAssetsAsync(string.Join(",", assetsInListView.Select(x => x.AssetId))); }
public static ICommand GetCommand(ListViewBase obj) { return((ICommand)obj.GetValue(CommandProperty)); }
private void ListView_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args) { stb_del_out.Begin(); _del_item = null; }
private static async Task ScrollIntoView( ListViewBase listViewBase, ScrollViewer scrollViewer, SelectorItem selectorItem, bool isVirtualizing, double previousXOffset, double previousYOffset, ItemPosition itemPosition = ItemPosition.Default, bool disableAnimation = false) { var transform = selectorItem.TransformToVisual((UIElement)scrollViewer.Content); var position = transform.TransformPoint(new Point(0, 0)); if (isVirtualizing) { var tcs = new TaskCompletionSource <object>(); EventHandler <ScrollViewerViewChangedEventArgs> viewChanged = (s, e) => tcs.TrySetResult(null); try { scrollViewer.ViewChanged += viewChanged; scrollViewer.ChangeView(previousXOffset, previousYOffset, null, true); await tcs.Task; } finally { scrollViewer.ViewChanged -= viewChanged; } } var listViewBaseWidth = listViewBase.ActualWidth; var selectorItemWidth = selectorItem.ActualWidth; var listViewBaseHeight = listViewBase.ActualHeight; var selectorItemHeight = selectorItem.ActualHeight; previousXOffset = scrollViewer.HorizontalOffset; previousYOffset = scrollViewer.VerticalOffset; if (itemPosition == ItemPosition.Left) { scrollViewer.ChangeView(position.X, previousYOffset, null, disableAnimation); } else if (itemPosition == ItemPosition.Top) { scrollViewer.ChangeView(previousXOffset, position.Y, null, disableAnimation); } else if (itemPosition == ItemPosition.Center) { var CentreX = (listViewBaseWidth - selectorItemWidth) / 2.0; var CentreY = (listViewBaseHeight - selectorItemHeight) / 2.0; var finalXPosition = position.X - CentreX; var finalYPosition = position.Y - CentreY; scrollViewer.ChangeView(finalXPosition, finalYPosition, null, disableAnimation); } else if (itemPosition == ItemPosition.Right) { var finalXPosition = position.X - listViewBaseWidth + selectorItemWidth; scrollViewer.ChangeView(finalXPosition, previousYOffset, null, disableAnimation); } else if (itemPosition == ItemPosition.Bottom) { var finalYPosition = position.Y - listViewBaseHeight + selectorItemHeight; scrollViewer.ChangeView(previousXOffset, finalYPosition, null, disableAnimation); } else if (itemPosition == ItemPosition.Default) { var bottomXPosition = position.X - listViewBaseWidth + selectorItemWidth; var finalXPosition = position.X; if (previousXOffset < position.X && previousXOffset > bottomXPosition) { finalXPosition = previousXOffset; } else if (Math.Abs(previousXOffset - bottomXPosition) < Math.Abs(previousXOffset - position.X)) { finalXPosition = bottomXPosition; } var rightYPosition = position.Y - listViewBaseHeight + selectorItemHeight; var finalYPosition = position.Y; if (previousYOffset < position.Y && previousYOffset > rightYPosition) { finalYPosition = previousYOffset; } else if (Math.Abs(previousYOffset - rightYPosition) < Math.Abs(previousYOffset - position.Y)) { finalYPosition = rightYPosition; } scrollViewer.ChangeView(finalXPosition, finalYPosition, null, disableAnimation); } }
private void ListViewOnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { args.ItemContainer.Tag = args.Item; args.ItemContainer.Tapped -= ItemContainerOnTapped; args.ItemContainer.Tapped += ItemContainerOnTapped; }
public async static Task ScrollToItem(this ListViewBase listViewBase, object item, SnapPointsAlignment alignment, bool highlight, double?pixel = null) { var scrollViewer = listViewBase.GetScrollViewer(); if (scrollViewer == null) { return; } var selectorItem = listViewBase.ContainerFromItem(item) as SelectorItem; if (selectorItem == null) { // call task-based ScrollIntoViewAsync to realize the item await listViewBase.ScrollIntoViewAsync(item); // this time the item shouldn't be null again selectorItem = (SelectorItem)listViewBase.ContainerFromItem(item); } if (selectorItem == null) { return; } // calculate the position object in order to know how much to scroll to var transform = selectorItem.TransformToVisual((UIElement)scrollViewer.Content); var position = transform.TransformPoint(new Point(0, 0)); if (alignment == SnapPointsAlignment.Near) { if (pixel is double adjust) { position.Y -= adjust; } } else if (alignment == SnapPointsAlignment.Center) { position.Y -= (listViewBase.ActualHeight - selectorItem.ActualHeight) / 2d; } else if (alignment == SnapPointsAlignment.Far) { position.Y -= listViewBase.ActualHeight - selectorItem.ActualHeight; if (pixel is double adjust) { position.Y += adjust; } } // scroll to desired position with animation! scrollViewer.ChangeView(position.X, position.Y, null, alignment != SnapPointsAlignment.Center); if (highlight) { var bubble = selectorItem.Descendants <MessageBubble>().FirstOrDefault() as MessageBubble; if (bubble == null) { return; } bubble.Highlight(); } }
public static void SetCommandParameter(ListViewBase obj, object value) { obj.SetValue(CommandParameterProperty, value); }
public static Brush GetColor(ListViewBase obj) { return((Brush)obj.GetValue(ColorProperty)); }
private void TestHistoryListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { args.ItemContainer.Background = Application.Current.Resources["CustomLightGrayGradientBrush"] as Brush; }
private void OnChoosingItemContainer(ListViewBase sender, ChoosingItemContainerEventArgs args) { var typeName = SelectTemplateCore(args.Item); Debug.Assert(_typeToItemHashSetMapping.ContainsKey(typeName), "The type of the item used with DataTemplateSelectorBehavior must have a DataTemplate mapping"); var relevantHashSet = _typeToItemHashSetMapping[typeName]; // args.ItemContainer is used to indicate whether the ListView is proposing an // ItemContainer (ListViewItem) to use. If args.Itemcontainer != null, then there was a // recycled ItemContainer available to be reused. if (args.ItemContainer != null) { if (args.ItemContainer.Tag.Equals(typeName)) { // Suggestion matches what we want, so remove it from the recycle queue relevantHashSet.Remove(args.ItemContainer); #if ENABLE_DEBUG_SPEW Debug.WriteLine($"Removing (suggested) {args.ItemContainer.GetHashCode()} from {typeName}"); #endif // ENABLE_DEBUG_SPEW } else { // The ItemContainer's datatemplate does not match the needed // datatemplate. // Don't remove it from the recycle queue, since XAML will resuggest it later args.ItemContainer = null; } } // If there was no suggested container or XAML's suggestion was a miss, pick one up from the recycle queue // or create a new one if (args.ItemContainer == null) { // See if we can fetch from the correct list. if (relevantHashSet.Count > 0) { // Unfortunately have to resort to LINQ here. There's no efficient way of getting an arbitrary // item from a hashset without knowing the item. Queue isn't usable for this scenario // because you can't remove a specific element (which is needed in the block above). args.ItemContainer = relevantHashSet.First(); relevantHashSet.Remove(args.ItemContainer); #if ENABLE_DEBUG_SPEW Debug.WriteLine($"Removing (reused) {args.ItemContainer.GetHashCode()} from {typeName}"); #endif // ENABLE_DEBUG_SPEW } else { // There aren't any (recycled) ItemContainers available. So a new one // needs to be created. var item = CreateSelectorItem(typeName); item.Style = Messages.ItemContainerStyleSelector.SelectStyle(args.Item, item); args.ItemContainer = item; #if ENABLE_DEBUG_SPEW Debug.WriteLine($"Creating {args.ItemContainer.GetHashCode()} for {typeName}"); #endif // ENABLE_DEBUG_SPEW } } // Indicate to XAML that we picked a container for it args.IsContainerPrepared = true; }
private void OnChoosingItemContainer(ListViewBase sender, ChoosingItemContainerEventArgs args) { var stickerSet = args.Item as StickerSetInfo; var cover = stickerSet.GetThumbnail(); var typeName = cover?.Format switch { StickerFormatTgs => "AnimatedItemTemplate", StickerFormatWebm => "VideoItemTemplate", _ => "ItemTemplate" }; var relevantHashSet = _typeToItemHashSetMapping[typeName]; // args.ItemContainer is used to indicate whether the ListView is proposing an // ItemContainer (ListViewItem) to use. If args.Itemcontainer != null, then there was a // recycled ItemContainer available to be reused. if (args.ItemContainer != null) { if (args.ItemContainer.Tag.Equals(typeName)) { // Suggestion matches what we want, so remove it from the recycle queue relevantHashSet.Remove(args.ItemContainer); } else { // The ItemContainer's datatemplate does not match the needed // datatemplate. // Don't remove it from the recycle queue, since XAML will resuggest it later args.ItemContainer = null; } } // If there was no suggested container or XAML's suggestion was a miss, pick one up from the recycle queue // or create a new one if (args.ItemContainer == null) { // See if we can fetch from the correct list. if (relevantHashSet.Count > 0) { // Unfortunately have to resort to LINQ here. There's no efficient way of getting an arbitrary // item from a hashset without knowing the item. Queue isn't usable for this scenario // because you can't remove a specific element (which is needed in the block above). args.ItemContainer = relevantHashSet.First(); relevantHashSet.Remove(args.ItemContainer); } else { // There aren't any (recycled) ItemContainers available. So a new one // needs to be created. var item = new ListViewItem(); item.ContentTemplate = _typeToTemplateMapping[typeName]; item.Style = sender.ItemContainerStyle; item.Tag = typeName; item.ContextRequested += StickerSet_ContextRequested; args.ItemContainer = item; } } // Indicate to XAML that we picked a container for it args.IsContainerPrepared = true; }
public static bool GetItemsBinding(ListViewBase obj) => (bool)obj.GetValue(ItemsBindingProperty);
private async void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; var stickerSet = args.Item as StickerSetInfo; var title = content.Children[1] as TextBlock; title.Text = stickerSet.Title; var subtitle = content.Children[2] as TextBlock; subtitle.Text = Locale.Declension("Stickers", stickerSet.Size); var cover = stickerSet.GetThumbnail(); if (cover == null) { return; } var file = cover.StickerValue; if (file.Local.IsFileExisting()) { if (content.Children[0] is Image photo) { photo.Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, 48); ElementCompositionPreview.SetElementChildVisual(content.Children[0], null); } else if (args.Phase == 0 && content.Children[0] is LottieView lottie) { lottie.Source = UriEx.ToLocal(file.Local.Path); } else if (args.Phase == 0 && content.Children[0] is AnimationView animation) { animation.Source = new LocalVideoSource(file); } } else { if (content.Children[0] is Image photo) { photo.Source = null; } else if (args.Phase == 0 && content.Children[0] is LottieView lottie) { lottie.Source = null; } else if (args.Phase == 0 && content.Children[0] is AnimationView animation) { animation.Source = null; } CompositionPathParser.ParseThumbnail(cover, out ShapeVisual visual, false); ElementCompositionPreview.SetElementChildVisual(content.Children[0], visual); UpdateManager.Subscribe(content, ViewModel.ProtoService, file, UpdateFile, true); if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(file.Id, 1); } } args.Handled = true; }
public static AnimationSettings GetItems(ListViewBase obj) => (AnimationSettings)obj.GetValue(ItemsProperty);
/// <summary> /// Initializes a new instance of the <see cref="ListViewBindableSelectionHandler"/> class. /// </summary> /// <param name="listView">The ListView.</param> /// <param name="boundSelection">The bound selection.</param> public ListViewBindableSelectionHandler( ListViewBase listView, dynamic boundSelection) { _handler = OnBoundSelectionChanged; Attach(listView, boundSelection); }
public static double GetInterElementDelay(ListViewBase obj) => (double)obj.GetValue(InterElementDelayProperty);
private void OnTravelGridContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { args.ItemContainer.Loaded += OnItemContainerLoaded; }
public static bool GetAnimateOnItemsSourceChange(ListViewBase obj) => (bool)obj.GetValue(AnimateOnItemsSourceChangeProperty);
private void HomeFeedGrid_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { args.ItemContainer.Loaded += ItemContainer_Loaded; }
private void Search_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { //var photo = content.Children[0] as ProfilePicture; //photo.Source = null; return; } var result = args.Item as SearchResult; var chat = result.Chat; var user = result.User ?? ViewModel.ProtoService.GetUser(chat); if (user == null) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; if (content == null) { return; } if (args.Phase == 0) { var title = content.Children[1] as TextBlock; title.Text = user.GetFullName(); } else if (args.Phase == 1) { var subtitle = content.Children[2] as TextBlock; if (result.IsPublic) { subtitle.Text = $"@{user.Username}"; } else { subtitle.Text = LastSeenConverter.GetLabel(user, true); } if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.TextBlock", "TextHighlighters")) { if (subtitle.Text.StartsWith($"@{result.Query}", StringComparison.OrdinalIgnoreCase)) { var highligher = new TextHighlighter(); highligher.Foreground = new SolidColorBrush(Colors.Red); highligher.Background = new SolidColorBrush(Colors.Transparent); highligher.Ranges.Add(new TextRange { StartIndex = 1, Length = result.Query.Length }); subtitle.TextHighlighters.Add(highligher); } else { subtitle.TextHighlighters.Clear(); } } } else if (args.Phase == 2) { var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36, 36); } if (args.Phase < 2) { args.RegisterUpdateCallback(Search_ContainerContentChanging); } args.Handled = true; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var radio = args.ItemContainer.ContentTemplateRoot as RadioButton; var content = radio.Content as Grid; var emojiPack = args.Item as EmojiSet; radio.Click -= EmojiSet_Click; radio.Click += EmojiSet_Click; radio.IsChecked = SettingsService.Current.Appearance.EmojiSet.Id == emojiPack.Id; if (SettingsService.Current.Appearance.EmojiSet.Id == emojiPack.Id) { _selectedSet = emojiPack; } radio.Tag = emojiPack; content.Tag = emojiPack; if (args.Phase == 0) { var title = content.Children[1] as TextBlock; title.Text = emojiPack.Title; } else if (args.Phase == 1) { var subtitle = content.Children[2] as TextBlock; var file = emojiPack.Document; var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { subtitle.Text = string.Format("{0} {1} / {2}", "Downloading", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { subtitle.Text = string.Format("{0} {1}", Strings.Resources.AccActionDownload, FileSizeConverter.Convert(size)); subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } else { if (SettingsService.Current.Appearance.EmojiSet.Id == emojiPack.Id) { subtitle.Text = "Current Set"; subtitle.Foreground = BootStrapper.Current.Resources["SystemControlForegroundAccentBrush"] as Brush; } else { subtitle.Text = emojiPack.IsDefault ? Strings.Resources.Default : "Downloaded"; subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } } } else if (args.Phase == 2) { var photo = content.Children[0] as Image; var file = emojiPack.Thumbnail; if (file != null && file.Local.IsDownloadingCompleted) { photo.Source = new BitmapImage { UriSource = UriEx.ToLocal(file.Local.Path), DecodePixelWidth = 40, DecodePixelHeight = 40 }; } else if (file != null && file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { photo.Source = null; _protoService.DownloadFile(file.Id, 1); } } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }