Xaml ListView strange behavior (Windows Phone 8.1) - c#

I am working on Windows Phone App (Windows Phone 8.1) and I have a strange behavior of my ListView control.
I have a ListView with text items (Sort of a chat) which is bound to ReadOnlyObservebleCollection to whom I am inserting items as I write a new message or when I receive a new one. I choose my ListView items template with my DataTemplateSelector.
The issue:
Sometimes, when my ListView is empty, I add a new message to my ListView I don't see it on the screen, but I can see that it in my collection and I know for sure that the RaisePropertyEvent is fired.
As I continue to add new item to the collection I can scroll down the list (there is some sort of placeholder in the first idex) and then I am seeing the rest of the items - except the first one.
I've also noticed that the missing item is getting to the DataTemplateSelector and it's returns the right template.
Getting weirder, when I am refreshing the view - all the items(including the first one) at their right places.
I guess there is something wrong with the first item generation but I don't get any binding exceptions or such.
Any help will be appreciated.

Same issue was occurring to me in my ListView. It was happening because listview was not loaded(loaded event was not fired) at the time first item was added to my observable collection. To fix this issue I start adding items in my observable collection after listview loaded event is raised.

Related

Accommodate custom item on winrt listview

I'm developing windows metro app. In my application, I've one Listview with wrapgrid in itemspanel to display list of items on vertical rows with specific height. I want to display one item on top of the first column of list view, which shows result/stats of list items.
I would like to know if it is possible without adding custom item to datasource of listview?
ListView has a Header property in which you can Place content before the ListViews Items.
As commented, I've implemented following solution which is not elegant but worked for me.
Use Datasource converter to add dummy item in main list. So, my original list remains as is.
Use Template Selector to bind different template for first item.
Handle Selection and clicked event of dummy item.

Not showing items with Visibility=Collapsed in Windows 8.1 GridView

I have a Windows 8.1 application with a GridView bound to a custom (sortable, deduplicated) observable collection. In this collection, I do some heavy filtering and setting an IsHidden flag for every item.
In the data template for the item, there is a condition making the item collapsed if IsHidden flag is set to true.
<Grid Width="160" Height="280" Visibility="{Binding IsHidden, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
This approach works in Windows Phone 8.1 XAML, making the items disappear from the ListView but it does not work in Windows 8.1 GridView. The problem with Windows 8.1 is that when I set an item in the collection to hidden, id disappears from the GridView but leaves an empty place, so there is a gap in the GridView.
Any ideas on how to solve it? Maybe same XAML style editing?
Here is a minimal solution to reproduce the problem: https://dl.dropboxusercontent.com/u/73642/gv.zip
I tried binding width and height of the items to the hidden flag and setting it to 0 when the item is hidden, but it did not help, still a gap in the GridView.
Update: One workaround would be filtering the actual bound collection, but this is not possible, because of some business requirements.
The problem is in the GridView's ItemsPanel.
Both ItemsWrapGrid and WrapGrid are uniform grids. All their child elements will be sharing the same height and width. That's why even if you collapse the ItemTemplate, the space is still reserved.
What you really need here is a WrapPanel. WINRT doesn't have a built-in WrapPanel but Jerry Nixon has built one and you can grab it from here.
After you updated your GridViews ItemsPanel, you still have one more thing to do. You need to also get the GridViewItem that hosts your Itemtemplate and set its Visibility to Collapsed.
private async void Button_Click(object sender, RoutedEventArgs e)
{
ds[5].IsHidden = true;
await Task.Delay(1000);
var gridViewItem =(GridViewItem)this.gv.ContainerFromIndex(5);
gridViewItem.Visibility = Visibility.Collapsed;
}
I put a little delay above to make the collapsing more obvious.
I tried your sample solution and changed it to a ListView instead. It exhibits the same behavior when the grid itself is hidden. I don't have XAML Spy to verify, but it appears that any List based control will allocate a rendered item for each item in the list.
I changed your click handlder to instead ds.RemoveAt(5); instead of hiding the item, and the element is removed from view with a nice animation. This appears to be as expected, and an interesting find.
It takes me a lot of time to understand the problem, and the solution right in front of my eyes. You trying to hide the item itself but the container still there, When you add an item to an GridView, the item is wrapped in an item container. from msdn :
" When you add an item to an ItemsControl, the item is wrapped in an
item container. For example, an item added to a ListView is wrapped in
a ListViewItem. Without UI virtualization, the entire data set is kept
in memory and an item container is also created for each item in the
data set. A ListView that's bound to a collection of 1000 items will
also create 1000 ListViewItem containers that are stored in memory."
You need to disable the container and create two DataTemplate and using DataTemplateSelector you can choose which DataTemplate for disable and active items. Check this useful article .

LongListSelector automatically at bottom

So I'm getting a weird behavior with the native LongListSelector from WP8.
It's ItemSource is bound to an
ObservableCollection<Group<Something>>
Everything is displayed correctly, but when the list appears on screen, I'm at the bottom of the list instead of it's top.
The only thing I do is to fill the ObservableCollection via it's Add() Method.
Is this a known behavior or is there a workaround ?
It is a normal behaviour as you are adding items one-by-one. for required behaviour kindly feed the list and then set it to observable collection

ListBox not updating

I am using a ListBox in one of the windows form application. When the screen first initializes, I am able to add/remove item into the listbox. However, after I click on one of the buttons to change the content of the listbox, the listbox does not update the values. I tried putting the Listbox inside a Panel and Refreshing the panel to no avail. Anyone ran into same problem?
It sounds as though the data source you are binding to does not support IBindingList.

WP7 Panorama items binding and adding other custom panorama items c#

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

Categories