In my Windows Phone 8 application I have use a LongListSelector control from the SDK to display hierarchical data.
How can I find out (from within my application button click handler) what the currently active (stacked on top) group header is? The SelectedItem might be null and therefore I cannot find the parent group from it.
If you don't have a selected item you'd have to use the ScrollOffset of the internal ScrollViewer to work out how much the list had been scrolled and then determine it based on the height of the items (and headers) that have been scrolled.
Related
I'm developing a Windows Store App which has a gridview that is used like a "Toolbox" from which I want to be able to drag items onto another control.
The default animation of dragging removes the item from the GridView while the item is being dragged and then the item snaps back to the GridView after the item is dropped on the destination component.
Is it possible/easy to allow the item (or items in the case of multi-selection) to be shown at the mouse/touch location during the drag while also remaining within the GridView?
The quick answer is no. Especially since you said "easy way". The concept of adorners which is in WPF isn't part of WinRT. You can always create something that floats under the pointer, for sure. That's a real option. But drag and drop is only partly implemented in W8.x XAML.
In my windows phone 8 application, I've used Long List Selector. When the user clicks on the show button in Main Page, I'm getting the result from the server and setting those results to Long List Selector, which is in Results Page. Up to this, everything is fine.
pageNumber = 1;
noOfResultsPerPage = 15;
Now, I want to add next 15 records to the Long List Selector when the user reaches to the last item. How should I know whether user scrolled to the last item in the list or not?
So that we can send the request to the server and get the records from the server and add to the list.
Thanks
If i'm right you want to implement incremental loading in the longlistselector, then you can use the itemrealized event of longlistseletor, there is a very nice sample which i would suggest you to have a look
You need to subscribe to ItemRealized event (this event is raised each time an item is rendered on the screen) So when the ItemRealized is raised you have to check the index of the iteam realized and then execute your method
I'm doing one windows phone 8 application. In this I've used list box. For the very first page I'm getting the data from server and adding that data to list box. Now I want to add Show More at the bottom of the list box i.e after the last item, to get the next items from the server.
How could I achieve this?
Hear you have to use Horizontal scrolling for load next data
Check below tutorial
Detect when a ListBox scrolls to its end (WP7)
Windows phone tutorial:Listbox
WP7 – How To Extend ListBox When Reaching Last Item
Windows Phone 7 ListBox Pagination with MVVMLight & ApplicationBar
we can Gets or sets the amount of data to fetch for virtualizing/prefetch operations by using
ListViewBase.DataFetchSize property and can Initiates the asynchronous request to load more data items, in accordance with the active incremental loading settings by ListViewBase.LoadMoreItemsAsync method.
If you want to do it by pagination then the following links may be helpfull for you
DataFetchSize method
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.listviewbase.datafetchsize.aspx
LoadMoreItemsAsync method:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.listviewbase.loadmoreitemsasync.aspx
You can see examples of using these here (though note that the sample was based on Windows 8 BUILD release and the apis have had some changes)
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/e71b7036-4fb7-4963-a65d-5bcb9fd8f664
I'll go ahead posting the logic as My code might not match with yours
So
1 -> Save the server data in an array or a list.
2 -> Design the xaml in a way that the Parent Grid has two or more rows with the last row for the show more. And the one before for the list. (Adjust height accordingly)
3 -> Populate it with a limited amount of data.
4 -> Next use the ListBox.Items.Add(data) method to add the data to the list. Keep sorted property off so that the elements are inserted at the bottom of the list
-> Go through the link Add Method for Observable Collections
Use step four on the show more button click .. and also adjust the height of the list or put it into a scrollviewer so that limited height scrolling can be done . olease update if further queries
I have a GridView in my main app page and I want to do some background processing for the items that are currently in view for the user (high priority), and then of course do the other items too (low priority).
I can access the ScrollBar and the ScrollViewer, but none of them appear to tell me which of my items are in the current scroll window. I could try to hack this in, but it gets tricky because the number of row/columns change based on the size of the scroll region.
http://msdn.microsoft.com/en-us/library/windows/apps/br209745.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.scrollviewer.aspx
Any help much appreciated!
thanks
There are two general ways you can do this. The first is to get the GridViewItem's AutomationPeer, which actually has a direct method to call. Class information here. I've had problems getting this to actually be usable though. Luckily, there's a second answer. It will require some math to be done, but it's doable.
Get the item container, in this case a GridViewItem, using the GridView's ItemContainerGenerator.
Get the GridView's ScrollViewer. You can search for FindVisualChild<T> methods, there are plenty around.
Do MyGridViewItem.TransformToVisual(MyGridViewScrollViewer).TransformPoint(new Point(0, 0)); This will get you the top left corner of the item, relative to the entire scrollable panel (known as its Extent) of the ScrollViewer (this will be important later).
This will return to you a Point object.
Next, we'll need to find out the range of X values that are currently being displayed in the ScrollViewer.
Note: If you're using a Vertical scrolling ScrollViewer, use the Heights. Horizontal, use the Widths. Both, use both. I am going to do my example using the Horizontal/Width.
Take the HorizontalOffset. This is your current 'lower bound' for the current viewable region.
Take the HorizontalOffset plus the ViewportWidth. This is the upper bound of the current viewable region.
If your Point.X is greater than your lower bound and less than your upper bound, then the item is visible.
If you further need to find out if the whole item is visible, do
this same calculation for Point.X + GridViewItem.Width.
Hope this helps, and happy coding!
You can use VisualTreeHelper to scan the visual tree as Nate suggests, but this is usually not recommended at runtime, especially for tight loops (e.g. checking lots of GridViewItem objects) or complex visual trees. You could do a minor improvement and only calculate the position of these items once and then do a simplified check based on the ScrollViewer.ViewChanged event and offset values, but that still seems a bit too complicated.
If your GridView uses an ItemsPanel that supports virtualization (e.g. the default WrapGrid) - most of the items that are actually loaded into GridView items are actually visible or not far off the screen, so if you bind your GridView to a collection of view models using ItemsSource - you can figure out when these items are accessed by binding to their properties or handling Loaded/Unloaded events on the ItemTemplate and call back to the view models to know when they are getting accessed. That way you can start loading these items when they first start showing up on screen and leave the logic to determine whether they should be loaded to the list control virtualization implementation in the platform.
Is there any event to handle then element is visual to user?
Example: There are some UI elements in the listbox but all the items are not visual, when user scrolls the listbox then element is visual. I want to identify that visual to handle read operation.
If you use the LongListSelector, rather than a ListBox you can use the ItemRealized event to know when a virtualized item has been realized (loaded).
If you really want to know when items are visible you'll have to measure the size of the items (if they're not all the same and known in advance), the size of the area that the ListBox (or LongListSelector) takes up (it'll vary for WVGA/WXGA & 720P screens) and the ScrollOffset of the internal (to the control template) ScrollViewer to calculate which items are currently visible.