Windows 8 series (11): Tips for development

Source: Internet
Author: User

Temporarily record and share some small development skills:

1. when binding data, if the data source needs to be cleared: collection. clear (); we recommend that you set the set to NULL: collection after the statement. clear (); Collection = NULL; (the error is reported because it is not set to null during development, windows. UI. XAML. DLL error)

2. The async void function and the async task function cannot be confused.

Async void functionname1 () {... await...; debug. writeline ("functionname1 over ")};

Async task functionname2 () {... await...; debug. writeline ("functionname2 over ")};

Section1: functionname1 (); debug. writeline ("functionname1 ");

Section2: await functionname2 (); debug. writeline ("functionname2 ");

The above two paragraphsCodeThe Code of Section1 is executed asynchronously. It is possible that functionname1 is output first, and functionname1 over is output. The second Code ensures that functionname2 is output after functionname2 over.

3. Does your code actually implement virtualization? You cannot simply check whether your code has written related controls, but you need to use the cleanupconfiguralizeditemevent event of the virtualizingstackpanel to determine whether virtualization is actually implemented. We modified the style in the style of the gridview, so that the above event is not triggered:

<Style X: Key = "  Paddinggridviewstyle  " Targettype = "  Gridview  " > <Setter property = "  Padding  " Value = "  0, 0, 0, 10  " /> <Setter property = "  Istabstop  " Value = "  False  " /> <Setter property = "  Tabnavigation  " Value = "  Once  " /> <Setter property = "  Scrollviewer. horizontalscrollbarvisibility " Value = "  Auto  " /> <Setter property = "  Scrollviewer. verticalscrollbarvisibility  " Value = "  Disabled  " /> <Setter property = "  Scrollviewer. horizontalscrollmode  " Value = " Enabled  " /> <Setter property = "  Scrollviewer. ishorizontalrailenabled  " Value = "  False  " /> <Setter property = "  Scrollviewer. verticalscrollmode  " Value = "  Disabled  " /> <Setter property ="  Scrollviewer. isverticalrailenabled  " Value = "  False  " /> <Setter property = "  Scrollviewer. zoommode  " Value = "  Disabled  " /> <Setter property = "  Isswipeenabled  " Value = "  True  " /> <Setter property = "  Itemcontainertransitions  " > <Setter. value> <transitioncollection> <adddeletethemetransition/> <contentthemetransition/> <reorderthemetransition/> <entrancethemetransition isstaggeringenabled = "  False  " /> </Transitioncollection> </setter. value> </setter> <setter property = "  Template  " > <Setter. value> <controltemplate targettype = "  Gridview  " > <Border borderbrush = "  {Templatebinding borderbrush}  " Borderthickness = "  {Templatebinding borderthickness} " Background = "  {Templatebinding background}  " Padding = "  1  " > <Scrollviewer X: Name = "  Scrollviewer  " Horizontalscrollmode = "  {Templatebinding scrollviewer. horizontalscrollmode}  " Horizontalscrollbarvisibility ="  {Templatebinding scrollviewer. horizontalscrollbarvisibility}  "  Ishorizontalrailenabled = "  {Templatebinding scrollviewer. ishorizontalrailenabled}  " Ishorizontalscrollchainingenabled = "  {Templatebinding scrollviewer. ishorizontalscrollchainingenabled}  " Isverticalscrollchainingenabled = " {Templatebinding scrollviewer. isverticalscrollchainingenabled}  "  Isverticalrailenabled = "  {Templatebinding scrollviewer. isverticalrailenabled}  " Tabnavigation = "  {Templatebinding tabnavigation}  " Verticalscrollbarvisibility = "  {Templatebinding scrollviewer. verticalscrollbarvisibility}  " Verticalscrollmode = "  {Templatebinding scrollviewer. verticalscrollmode}  "  Zoommode = "  {Templatebinding scrollviewer. zoommode}  " > <Grid margin = "{templatebinding padding}"> <Itemspresenter headertemplate = "  {Templatebinding headertemplate}  " Header ="  {Templatebinding header}  " Headertransitions = "  {Templatebinding headertransitions}  " /> </GRID> </Scrollviewer> </Border> </controltemplate> </setter. value> </setter> </style>

The red part of the code causes the virtualization to be damaged. After modification

<Scrollviewer X: Name ="Scrollviewer"...> <Itemspresenter headertemplate ="{Templatebinding headertemplate}"Header ="{Templatebinding header}"Margin ="{Templatebinding padding}"Headertransitions ="{Templatebinding headertransitions}"/> </Scrollviewer>

 

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.