Windows Phone 12, designer sync

Source: Internet
Author: User
Tags blank page

to add a data source to a page during design stage

The visual designer of blend or VS will run our code and then show that when we build, the designer goes into the page's constructor, calls InitializeComponent (), and renders the UI rendering to us.

Designmode.designmodeenabled gets a value that indicates whether the process is running in design mode.

d:datacontext= "{d:designinstance type=data:mainpageviewmodel,isdesigntimecreatable=true}"

1 <Page2     x:class= "Myapp.mainpage"3 xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"4 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"5 xmlns:local= "Using:myapp"6 xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"7 XMLNS:MC= "http://schemas.openxmlformats.org/markup-compatibility/2006"8 mc:ignorable= "D"9 Background="{ThemeResource Applicationpagebackgroundthemebrush}"Ten DataContext="{Binding Viewmodel,relativesource={relativesource mode=self}}" One D:datacontext="{d:designinstance Type=local:mainpageviewmodel,isdesigntimecreatable=true}"> A  -     <Grid> -         <TextBlockText="{Binding Name}"/> the         <ListViewItemsSource="{Binding person}"> -             <listview.itemtemplate> -                 <DataTemplate> -                     <Border +                         BorderBrush= "Hotpink" - borderthickness= "5" + Padding= " the" A Margin= "Ten"> at                         <StackPanel> -                             <TextBlock -                                 FontSize= " the" - Text="{Binding Id}"/> -                             <TextBlock -                                 FontSize= "+" in Text="{Binding Name}"/> -                         </StackPanel> to                     </Border> +                 </DataTemplate> -             </listview.itemtemplate> the         </ListView> *         <!--<border $ borderbrush= "Hotpink"Panax Notoginseng borderthickness= "5" - padding= " the margin= "Ten" > + <StackPanel> A <textblock the fontsize= " + text= "one"/> - <textblock $ fontsize= " $ text= "Zhang"/> - </StackPanel> - </Border> - the     </Grid> - </Page>
1 namespaceMyAPP2 {3     /// <summary>4     ///a blank page that can be used for itself or to navigate inside a Frame. 5     /// </summary>6      Public Sealed Partial classMainpage:page7     {8          PublicMainpageviewmodel ViewModel {Get;Set; }9          PublicMainPage ()Ten         { OneViewModel =NewMainpageviewmodel (); A              for(inti =0; I < -; i++) -             { -VIEWMODEL.PERSON.ADD (Newperson {Id =1, Name ="Hello" }); the             } -              This. InitializeComponent (); -  -              This. Navigationcachemode =navigationcachemode.required; +         } -  +         /// <summary> A         ///called when this page will be displayed in Frame.  at         /// </summary> -         /// <param name= "E" >describes how to access event data for this page.  -         ///This parameter is typically used for configuration pages. </param> -         protected Override voidonnavigatedto (NavigationEventArgs e) -         { -             //TODO: Prepare the page shown here.  in  -             //TODO: If your application contains multiple pages, make sure to             //Handle the hardware Back button by registering the following event: +             //Windows.Phone.UI.Input.HardwareButtons.BackPressed event.  -             //If you use the Navigationhelper provided by some templates, the             //the event will be handled for you by the system.  *         } $     }Panax Notoginseng     //to preview data binding results in the designer -     //The first step: Make some false data in the constructor of the view model, put it in the IF (designmode.designmodeenabled), in order to perform efficiency, plus # if DEBUG the     //Step Two: the node defined in the data source page is defined D:datacontext +     //d:datacontext= "{d:designinstance type=local:mainpageviewmodel,isdesigntimecreatable=true}" A      Public classMainpageviewmodel the     { +          PublicMainpageviewmodel () -         { $person =NewObservablecollection<person>(); $ #ifDEBUG -             //The designer will also run our code -             if(designmode.designmodeenabled) the             { -                  for(inti =0; I < -; i++)Wuyi                 { thePerson.add (Newperson {Id = i, Name ="Designer" }); -                 } WuName ="Little Black"; -             }  About #endif $         } -          Publicobservablecollection<person> Person {Get;Set; } -          Public stringName {Get;Set; } -     } A      Public class Person +     { the          Public intId {Get;Set; } -          Public stringName {Get;Set; } $     } the}

Windows Phone 12, designer sync

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.