I have a Listbox that bind to an ObservableCollection. In my app, I need to clear this collection in OnNavigatedFrom and read it in OnNavigatedTo to reduced memory.
However, I see that when using StackPanel as ItemsPanelTemplate, Listbox can remember its last view (its seletected item), while VirtualizingStackPanel does not.
So how can I disable this behavior when using StackPanel ?
It is a common problem, you need to set the Listbox's SelectedIndex to -1
Related
I just want to create a list with data and columns (sortable). I don't want tiles, I don't want right scrolling. I just want a list like the "Listview" Win32 common control. Or am I forced into the tile metaphor.
I believe they are not at a metaphor but from my point ListView in Win32 is one.
ListView in Win32 is a very limited control, unflexible and too ugly.
ListView and GridView xaml controls are far better aproach, I know.. switch from old style controls to new style is easy if you come from scratch but if you have old style background... is hard... I know.
If your lvw32 grows vertically based on data use a Listview (xaml) in wich each item is a Row and use the item template to put in a gridview,the gridview will be one register with all attributes (columns).
So your ListView will have a collection of Rows, each Row is a GridView who is a Collection of attributes.
This is a way, but you have a lot of different options.
so I have a question regarding my stackpanel I'm using.
Basically when I keep adding items (expenses/earnings) the into the stackpanel I will eventually be short on navigational space and ultimately the older entries be overwritten.
So at the moment it has a maximum of five entries that can be added and displayed all at one. However If I add another entry/item/expense etc the first entry will be removed/not seen in the stackpanel
So in the picture, as soon as a 6th item is added the 1st item in the list will be removed/not visible
Kind of hard to explain, hope you can help!
More code:
pivotItem XAML
ItemsList control XAML
put the stackpanel in a scrollviewer. This should allow for automatic resizing as more data is added and you can scroll through it as well
I use listbox.ScrollIntoView(item), but as long as this item is in listbox view, it won't scroll.
Actually I want the item to be centered in the listbox's view. Is there anyway to do this?
Unfortunately this is not all that easy, it depends on whether your listbox is virtualized or not, which depends on the panel that it uses to render its contents. For a non-virtualizing listbox, you can set the vertical scroll position by invoking the following method on the ScrollViewer which is part of the listbox template, where offset is in pixels.
ScrollViewer.ScrollToVerticalOffset(offset);
For virtualizing, you can invoke the following method on the VirtualizingStackPanel, where offset is the list location (you can use a double value, i.e. scrolling to 3.5 will scroll to half way between index 3 and 4):
ItemsHostStackPanel.SetVerticalOffset(offset);
For how to use this code in context, look at the jump list control I implemented here:
http://wp7contrib.codeplex.com/SourceControl/changeset/view/72741#1502048
I have a peculiar problem in Windows Phone Development. I have 4 panorama items each of them containing a webBrowser control. On the start of the application, I have only the first panorama item visible while the remaninig are in collapsed state.
Based on the interaction in the first webBrowser, we Notify the WP7 app (webBrowser.ScriptNotify event) and decide which panoramaitems to display. The visiblity is set in the delegate that handles the ScriptNotify event.
the issue I am facing is that though i set the visibility in the delegate to Visible, it doesn't show up in the Panorama. I have tried using Dispatcher in the delegate to change visibility but it hasn't helped:
Deployment.Current.Dispatcher.BeginInvoke(() => {
discussions.Visibility = System.Windows.Visibility.Visible;
});
Can someone suggest what i could be doing incorrectly?
First of all, you shouldn't use a WebBrowser control inside a Panorama. It's very bad performance.
Secondly, Panorama and PivotItems don't have a collapsed state.
And thirdly, the dispatcher have nothing to do with this (unless you're not running the code on the UI thread).
So what you need to do, is to add the PanoramaItems dynamically to the Panorama control. This can be done by databinding (recommended), or directly from C#.
I don't know about performace but i'm sure that a PanoramaItem has a collapsed *visibility* state i tried to toggle it from code and it works like a charm if the initial state is visible.
But if the initial state is collapsed when the panorama loads then it doesn't work anymore. I guess it is because if it is collapsed then it is not included in the panorama and so it won't be visible when you set it to visible.
Maybe that's a bug or i don't know but it is a bit awkward.
To add the PanoramaItem to the Panorama could work.
I'm sorry for not answering the question but the other way around, enforcing the problem :) .
I do have the same problem, one PanoramaItem with an ItemsControl databounded to a collection of the ViewModel. The PanoramaItem visibility property is databounded to {Binding} and a CollectionToVisibility converter is used. During debug with a breakpoint set inside the converter code I managed to see that the return value is ok but the PanoramaItem is not visible when the collections has items.
My investigation took me to realize that in fact when the first get to the Collection occours the return value is null because the Collection data comes from a async call to a service and the converter return value is Visibility.Collapsed, and only when the Collection is populated and the PropertyChanged event is raised, the second get to the Collection property triggers the databind refresh and the return value of the converter is now Visibility.Visible, this leeds me to think that the PanoramaItem isn't included in the Panorama control tree during the applytemplate because the visibility is set to collapsed, and after that the UI never loads the PanoramaItem again.
I made a test to verify this scenario returning in the get of the Collection property an hardcoded list of items so that the first get have items in it and the converter returns Visible in the first get request.Everything works like a charm.I can even string the collection out of items and it gets collapsed and the other way around.
All this is pure Xaml, no code behind.
The intent of this is to hide PanoramaItems that for some reason does not have content to show.
Basically, the panorama keeps an internal list of visible item. This list isn't updated when you set an item to visible. The easiest way to force the control to update this list is setting the MainItem property. So after setting the visibility of your panorama item, just add the following line:
yourPanorama.DefaultItem = yourPanorama.DefaultItem;
(given that the panorama is called yourPanorama)
I have listbox in WP7 where i need to scroll to certain items according to user choice and i use scrolltoview for that. Problem is that i need listbox to scroll listbox enough so that selected item appears aligned to top edge. Right now scrolled item is positioned at bottom.
Assuming that you have fixed (and known) size items and a fixed (and known) size of listbox, can't you just account for the number of items between the top and bottom of the visible space and adjust your offset accordingly?
Unfortunately Matt solution was unusable in this case because listbox items were too big taking almost whole screen per item. But i was able to solve this problem by getting scrollviewer of listbox and use its scroll method to scroll into listbox SelectedIndex. Item is still not positioned perfectly after scrolling but height difference is minimal and acceptable for me.