I have a list box bound to a collection of items.
Whenever i call a Refresh on a CollectionView of bound items the adorners disappear from list box items.
Can somebody explain why and how i can overcome this?
Should i re-add adorners after each refresh?
An adorner is linked to a particular element, in your case it seems like you are adorning ListBoxItem elements.
When you call the Refresh method on the collection view, this will cause the ListBox control to delete all of its existing ListBoxItem children and recreate them. Your adorners are "disappearing" because the elements they are adorning have been deleted by the list box.
You can either recreate the adorners or try to find some way of refreshing your list box that doesn't involve refreshing the collection view.
Related
I'm using a Multiselect Treeview in MVVM WPF App. A ReactiveCollection is binded as the treeview source. Implemented paging mechanism internally for the source and populated the collection with dummy items.
Now I need to how many items (rows) in the treeview are actually visible in the GUI at any point of time and when the user scrolls. Basically, I want to know the first and last item index in the visible view at any given time and I will implement paging based on this item(row) index and scrolling.
And this logic to detect item index must be implemented as a behaviour for itemscontrol, so that I can reuse it for any itemscontrol.
I have a ListView which I am constantly adding items in.
I am able to scroll while the items in the ListView were being added.
However, upon selecting an item in the ListView, I am unable to scroll while items are being added. For each ListView.Items.Add(Object) I call, I will revert to the focus of the item initially selected.
Clearing the SelectedItems and SelectedIndices, I am still able to continue scrolling down the ListView as I keep popping back to the originally selected item anytime an item is added.
Could anyone advise how to get past this problem?
Thank you.
Regards,
Michael
If you're using WPF, are you using an ObservableCollection? It sounds like the DataContext is being changed causing the ListView to reload. If you bind to an ObservableCollection you may have more luck.
I have a DataGrid with a bunch of rows representing items in my system. I want that each time a user selects an item in the grid (the user is allowed to select multiple items) the item will be added to a StackPanel and have its own datatemplate using an Expander to display its data.
Can anyone help me do this in WPF?
Thanks!
John.
I wouldn't use a StackPanel, but an ItemsControl, and bind its ItemsSource to the DataGrid's SelectedItems. However, at the moment I'm not sure whether SelectedItems has change notification. If not, you might have to use a CollectionViewSource in between, and call CollectionViewSource.Refresh during the DataGrid.SelectionChanged event.
how can i bind SelectedItems of a ListView?
My ListView has multipleSelection attribute and I'm using CollectionView for its contents..
I've heard about Attached property and I tried implementing this with the one I found here:
Sync SelectedItems in a muliselect listbox with a collection in ViewModel
I can multiple select the items by clicking rows but I can't use the Shift keyboard for multi-selecting many rows instantly... Also, when I filter my collection and refresh it, my selection are all deselected after the refresh..
How can I make it so that whenever my CollectionView refreshes, the previously selecteditems are still selected after the refresh...?
Can someone also help me how to manipulate logically the selected items through my viewmodel?
May be you should add the IsSelected property to the ListViewItem's view model.
You will have to use your own code to keep the selected items after a refresh. Maybe make a copy of your collection before the refresh and afterwards a simple for to check all the checked items in your current collection.
Change your selectection mode to extended for your listbox for the shift key to work.
As for manipulating logically the selected items, you will have to give a lot more info on what exactly you want done.
I am running into an issue where i am using a panorama control and binding it to a datasource. But i still do want other custom items on another panorama items where i need a textblock, a grid and so on. So if i am adding it in the backend it doesnt show up those panorama items. It just shows the datasource binded items. Why is that so? Both of them should work out.
Can anybody help me with a solution for this.
Thank You.
Since you're wanting to manually add PanoramaItems, I can think of two approaches:
Make sure your Panorama.ItemsSource is set to an ObservableCollection that is accessible in the code behind or viewmodel, and then add your new items to that ObservableCollection which should update the Panorama.
Don't databind the Panorama control's Items - just add items manually when you want them.
Either way, the Panorama's ItemTemplate gets evaluated when the items are added to the underlying collection, so using a DataTemplateSelector will allow your code to determine which DataTemplate to apply when the new item is added without affecting the templates for previous items.
/chris