Windows Phone development and learning-dynamic loading of data

Source: Internet
Author: User

In Windows Phone development, the ghost control is often used. Unlike the panorama control, the ghost control is similar to a roller and is connected at the beginning and end. This control can be used when many pages are consistent with the general framework.

However, sometimes we do not know the number of items in items accurately, so we need to implement dynamic loading of data in partitions. Dynamic Loading means to dynamically create the number of pivotitem and write data to pivotitem dynamically. For the sake of simplicity, the same list is created in each javastitem.

First, the project directory is shown as follows:

The mainpage layout is as follows:

The textbox is used to fill in the number of required titem values to be generated. click the button to go to the detail page. The number of items is the one you just filled in. For example, after entering 3, the result is as follows:

The project mainly contains two Cs classes and two XAML files.

Vmlocator. CS is mainly used to receive and save user input numbers and create a class that generates a response page.

CodeAs follows:

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. windows; namespace TT {public class vmlocator {Private Static vmlocator _ instance; public static vmlocator instance {get {If (_ instance = NULL) {_ instance = application. current. resources ["locator"] As vmlocator;} return _ instance;} private detailviewmodel _ detailvm; Public detailviewmodel detailvm {Get {return _ detailvm ?? (_ Detailvm = new detailviewmodel ());}}}}

Note that app resources are used and saved as key-value pairs. Therefore, you need to add resources in APP. XAML.

<Application X: class = "TT. APP "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: Local =" CLR-namespace: TT "xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "> <! -- Application resources --> <application. Resources> <local: vmlocator X: Key = "locator"/> </application. Resources> <application. applicationlifetimeobjects> <! -- Required object that handles lifetime events for the Application --> <shell: phoneapplicationservice launching = "application_launching" Closing = "application_closing" activated = "application_activated" Deactivated = "application_deactivated"/> </application. applicationlifetimeobjects> </Application>

Detailviewmodel. CS: Creates a specified titem based on the number entered by the user and assigns a value to each item (list is created here)

The Code is as follows:

Using system; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. ink; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using system. componentmodel; using system. collections. objectmodel; using system. collections. generic; namespace TT {public class detailviewmodel: In Otifypropertychanged {private observablecollection <testbench> _ binddata; Public observablecollection <testbench> binddata {get {return _ binddata;} set {_ binddata = value; raisepropertychanged ("binddata ");}} public detailviewmodel () {} public void adddata (INT size) {binddata = new observablecollection <testable> (); For (INT I = 0; I <size; I ++) {testbench T = new testbench (); T. name = "pi OVT item "+ I; T. listdata = new list <string> (); For (Int J = 0; j <10; j ++) {T. listdata. add ("list item" + J);} binddata. add (t) ;}# region inotifypropertychanged public event propertychangedeventhandler propertychanged; private void raisepropertychanged (string propertyname) {If (propertychanged! = NULL) {propertychanged (this, new propertychangedeventargs (propertyname) ;}# endregion} public class test.pdf {public string name {Get; set ;} public list <string> listdata {Get; Set ;}}}

In mainpage. XAML, the button RESPONSE event is as follows:

 
Private void button#click (Object sender, routedeventargs e) {vmlocator. instance. detailvm. adddata (Int. parse (textbox1.text. tostring (); navigationservice. navigate (New uri ("/detailviewpage. XAML ", urikind. relative ));}

The code for detailviewpage. XAML is as follows:

<Phone: phoneapplicationpage X: class = "TT. detailviewpage "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "xmlns: Controls =" CLR-namespace: Microsoft. phone. controls; Assembly = microso Ft. phone. controls "xmlns: D =" http://schemas.microsoft.com/expression/blend/2008 "xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "MC: ignorable =" D "D: designwidth =" 480 "D: designheight = "768" fontfamily = "{staticresource quota}" fontsize = "{staticresource quota}" foreground = "{staticresource phoneforegroundbrush}" supportedorientations = "portrait" orienta Tion = "portrait" datacontext = "{binding detailvm, source = {staticresource locator}" shell: systemtray. isvisible = "true"> <! -- Layoutroot is the root grid where all page content is placed --> <Phone: phoneapplicationpage. resources> <datatemplate X: Key = "dt_detail"> <ListBox itemssource = "{binding listdata}"> <ListBox. itemtemplate> <datatemplate> <textblock text = "{binding}"/> </datatemplate> </ListBox. itemtemplate> </ListBox> </datatemplate> <datatemplate X: Key = "dt_header"> <textblock text = "{binding name}"/> </datatemplate> </Phone: phoneapplicationpage. Resources> <! -- Layoutroot is the root grid where all page content is placed --> <grid X: Name = "layoutroot" background = "Transparent"> <! -- Revoke control --> <controls: detail Title = "my application" itemtemplate = "{staticresource dt_detail}" headertemplate = "{staticresource dt_header}" itemssource = "{binding binddata}"> </controls: platform> </GRID> </Phone: phoneapplicationpage>

We can see that the data binding and data template are used above, so that the producer can dynamically bind data. Of course, if you need to customize the bound data, you only need to modify the adddate () function in detailviewmodel. cs. I believe it is quite convenient.

Finally, we have to say that although the scheme can achieve dynamic data loading, it does not mean this is a good method. The number of items in items should not be too large, otherwise the user experience will be greatly reduced. I personally think 3-4 are enough, so it is best to limit the number of dynamic loads to less than 4. I have posted a problem on stackoverflow before, and the same is recommended.

From a design perspective and given the unknown number of calendars, I don't think a seconds is what you shoshould use. If you take a look at the design
Guidelines, you'll note:

Apps shoshould Minimize the number of pages (four pages or fewer ). users can become lost if they jump from response page to response page. use existing controls sparingly and limit the use of temporary pages to scenarios where it's appropriate for the experience.

And

the specified control shocould be used only to display items or data of similar type (for example, filtered views of the same data ).

The latter doesn' t preclude what you are doing, but most of the apps that I 've seen use them Ts to provide alternate views of the same data versus the same view of different data (as you 'd be doing ).

I think a simple list of the available calendars that navigates to a second page for the calendar (with binding to your specific calendar's view model) wocould be easier and more intuitive.

In fact, I always think that the Windows Phone interface should be different from the IOS Android interface. Otherwise, what should we do with Windows Phone? Unique is the magic weapon for Nokia and Windows Phone to survive and grow. Everything else is a cloud. Good luck to programmers who develop Windows phone8 applications. We look forward to a more ingenious design for Windows phone8 designers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.