So in Windows 8 Metro (using C#/WinRT), I have a data structure as follows:
public class Comment
{
public string body;
public List<Comment> replies;
}
and would like to show it on a page, but previous methods are now unavailable in WinRT (TreeView and HeirarchicalDataTemplate). Is there anyway to do so now, in Windows 8? Thanks so much for the help!
Other than implementing the TreeView control or looking for one already implemented - you could have a Frame with a ListView that has its ItemsSource bound to a list of Comments. You would wire up the ListView in such a way that tapping a comment would navigate to another Page in the Frame with a ListView and a list of replies bound to it. A back button would navigate back in the Frame to get you back to the Page for parent comment.
EDIT*
WinRT XAML Toolkit has a TreeView control now. Check it out: http://winrtxamltoolkit.codeplex.com/SourceControl/changeset/view/b0ee76bd6492#WinRTXamlToolkit/Controls/TreeView/TreeView.cs
Take care though - this is just a rough port from Silverlight Toolkit and might not work so well. Also if you are planning on releasing it as part of a Windows Store application - you would need to heavily restyle it unless your app is desktop-only since it is not very touch-friendly.
Related
I am doing xamarin development and I am not doing forms.
I want to go back by 3 viewcontrollers/activities but goback method is for going back by one viewcontroller or activity
If I use navigateto i believe one more time the viewcontrolller/activity gets added.i.e two instances.
So how to solve this problem ?
Update:
Here is the inavigation interface there is no way to access thr navigational stack as well
If you are going back, then use INavigationService.GoBack();. You can call that 3 times in a row to go back 3 pages.
private void GoBackThree()
{
_navigationService.GoBack();
_navigationService.GoBack();
_navigationService.GoBack();
}
I haven't used MVVM Light before but I have quite a bit of experience of Xamarin Forms. I used to use MVVM Cross for navigation but eventually found that the built in Xamarin Forms Navigation was much better, I ran into similar scenarios as to what you have here.
Under the hood it looks like MVVM Light is just wrapping the Xamarin Forms Navigation anyway - http://mvvmlight.codeplex.com/SourceControl/latest#Samples/Flowers/Flowers.Forms/Flowers.Forms/Helpers/NavigationService.cs
I don't think you need give up on MVVM Light navigation but you do need to get under the hood to achieve the navigation without seeing three transitions. I haven't tried this with MVVM Light but it works great with normal Forms navigation.
Step 1
Get access to the underlying Xamarin Forms navigation:
var navigation = Application.Current.MainPage.Navigation;
Step 2
Remove the two pages you want to skip when navigating back. It's important that you remove them before navigating backwards otherwise you'll get a double transition (note the -2 is because you want to remove the second to last page).
var firstPageToRemove = navigation.NavigationStack[navigation.NavigationStack.Count - 2];
navigation.RemovePage(firstPageToRemove);
var secondPageToRemove = navigation.NavigationStack[navigation.NavigationStack.Count - 2];
navigation.RemovePage(secondPageToRemove);
Step 3
Navigate backwards
_navigationService.GoBack();
I hope that works for you.
Alternative Consideration
I have a similar application in my app which I've solved a little more elegantly. If you know you never need to be able to navigate back to those previous pages. When you push the new pages on, you can actually remove the previous one if you no longer need it. Please note you have to remove the page after you push on the new one otherwise you get two transitions. I use this extension method on-top of the standard Forms Navigation which I showed you how to access in Step 1 to achieve it.
public static async Task ReplaceCurrentAsync(this INavigation navigation, Page page, bool animated = false)
{
var curentPage = navigation.NavigationStack.Last();
await navigation.PushAsync(page, animated);
navigation.RemovePage(curentPage);
}
I have a large list of items, so i should request corresponding page from the server. How to catch an event, when user scrolls to the end of the listbox, so i can request another page?
The exact solutions you are looking for: http://danielvaughan.orpius.com/post/Scroll-Based-Data-Loading-in-Windows-Phone-7.aspx
You're thinking about data virtualization. Shawn Oster wrote a really good explanation to this here. To sum it up, it's not the ListBox that is managing your data, but your custom IList implementation, that is able to fetch new items each time a new data chunk is needed.
you can just check the vertical offset if is greater than the scrollable height, the user is at the bottom of the list, fire the request for another page as needed.
The best approach is to use the LongListSelector. It's available from the Windows Phone Toolkit for Windows Phone 7 or it's built-in on Windows Phone 8. It performs better than the built-in ListBox and has more features.
A post from the official Windows Phone Developer blog (from October 2012) gives all the details and tells how to setup infinite scrolling.
I am new the WP7.1. I am developing chat app, in that there is screen like friends, in that screen it like 1000s of friends are there, We are binding to longlistselector the using sqlite.
Main problem is like, we have one API for calling friend's update like (displayname, profile picture etc) and I am processing the API data and binding the data to longlistselector, at the time of binding, I am not able to scroll the longlistselecor and any other buttons in the screen.
I am binding the data using Deployment.Current.Dispatcher.BeginInvoke(() => { Binding to }); and Dispatcher.BeginInvoke(() => { Binding to }) and BackgroundWorker (I tried those many ways).
Please suggest any solutions binding the without disturbing UI.
Thanks in advance.
-- Chandra
Whenever you push data on the screen (be it through XAML {Binding} or through directly accessing the page's UI elements) it needs to be done on the UI thread. While the UI thread is busy with processing your code or with redrawing the UI because of your code, the UI freezes.
This means that you need to make everything inside BeginInvoke() as short and efficient as possible. However you also need to make as few calls to BeginInvoke() as possible. Finding the balance between these will determine the experienced speed of your UI.
In the case of LongListSelector I found that it's efficient to add 50 items at a time, wait half a second and add the next 50 items. Your mileage may vary.
I try to migrate my iphone app to wp7.
On ios, UITableview is well designed, and very easy to code.
I have the some book about wp7, but there are no detail concerned about moving and removing of a row of listbox.
Welcome any comment
I'd like to think that Windows Phone is also well designed. :)
To simply remove an item from a ListBox in your codebehind, you need to get a reference to the ListItem that you want to remove. For example, to remove the currently selected item:
var myListItem = myListBox.SelectedItem;
Then you can remove it with:
myListBox.Items.Remove(myListItem);
In order to address your question about moving items, we'd need to know more about how you're populating the ListBox. Are you using databinding, or adding items with myListBox.Items.Add(myListItem)?
If I needed to move items between two lists, I would create a public List<MyItem> property for each list and databind each list to its own ListBox. Then I might do something like this (working from memory here):
var itemToMove = myList1.Remove(myListBox1.SelectedItem);
myList2.Add(itemToMove);
myListBox1.DataBind();
myListBox2.DataBind();
There's a much better way to do this, using INotifiyPropertyChanged, but I suspect you need to play around with the basics for a while to get comfortable in C#.
Bonus tip: Windows Phone is very similar to Silverlight, and you can usually find more information if you search for Silverlight examples.
In WP7, usually we set the ItemSource of listbox, when our source changes its changes automatically propagate to the UI due to data binding ( it is known as one way binding ; source to UI ).
so what ever you do ( add, update or delete) in itemsource, it reflects to UI.
databinding in wp7
As my app gets bigger I am finding that the same type of entity is appearing more and more throughout, typically in a listbox.
When someone taps on the entity, I want to navigate to the detailed view of this entity.
An example of this would be a product: it appears in a product list by category, it appears in search results, or it might appear as a saved favourite. In my instance, all of these would come from a table in local SQLCE storage.
Every time I surface the entity in some way that someone could tap on it, I basically cut the same code: subscribe to the SelectionChange event on the listbox, extract the entity, use MVVM Light messaging to signal that the selected entity has changed, then call NavigationService to do its business.
Has anyone worked on something similar and, if so, what have you came up with? Or more importantly, if there's some MVVM Light toolkit convention that I'm overlooking, could you please point me in the right direction?
Are you calling the NavigationService from code-behind or the View Model now? If the former, you could check the WP7 Navigation arcticle by LBugnion for triggering it from the VM. If you combine that with the EventToCommand behavior (like in here) you should be able to create a nice and clean "MyEntitySelected" command in the VM which takes the entity as a parameter.
I think the question here is, how do I deal with this without cut/paste the same code each time? If this is the case, maybe trying to package the entity/listbox thing in a XAML usercontrol! Take a look at this: http://www.windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps
Then if the representation needs to be different, you could have a look at this: http://www.windowsphonegeek.com/articles/Implementing-Windows-Phone-7-DataTemplateSelector-and-CustomDataTemplateSelector ( this example does different styling in one listbox, but you can change this to only apply different style on each different page with a listbox on it )