The blog should have been posted last weekend, dragged and dragged to the present Friday, but there is one last blog post on weekends. T T
Because last week did not lecture content, see the students do better to show the results, some do games, some write life applications, some ideas peculiar, some technical excellence, some packaging gorgeous ... I have to say that every student has a very good idea, I also feel that there is a stable team and a clear group division is how efficient things, but I am a team in the process of writing to spend too much time, if there is a team to communicate, I feel I can do better.
Next I'll talk about some of the things I learned in the process of writing code.
1.WP Navigation and window jumps in WPF.
First of all, the implementation of the two are different, in the WP basic page jump only need a line of code can be implemented, very convenient, my code in a jump as follows:
var passId = String.Format ("{0}", ((TextBlock) e.originalsource). Name); Frame.navigate (typeof(courseinfo), passId);
Frame.navigate (typeof ([page name]), [pending parameters]), basic format as follows, the following parameters are optional, see the actual need can be passed different types of parameters.
However, the jumps in WPF are different.
First, WPF is divided into Windows and pages, which differ from each other's jumps. Window Windows contains the page instead of the page containing the window.
Landing interface of the jump, that is, the window switch, can be written as follows:
New coursetable (); Ct. Show (); this. Close ();
Here coursetable is the name of the destination window, where you first instantiate it, and then call Show () This member function to display it.
Page jump is divided into the front and back to the background turn, the front can be as follows:
<textblock fontsize= "textwrapping="Wrap" margin= "0,0,0,-19.998"> "lnkpre" navigateuri="Page2.xaml" foreground="Black" > Enter Page2 </Hyperlink></TextBlock>
Background transfers can be in several ways, such as:
Navigationservice.getnavigationservice (this). Navigate (new Uri ("page2.xaml", urikind.relative)); Navigationservice.getnavigationservice (this). GoForward (); Turn back Navigationservice.getnavigationservice (this). GoBack (); Go ahead.
In the background jump, there is also a simpler usage:
This New Page2 ();
Then the window jump page can be written as follows:
New NavigationWindow (); New Uri ("page1.xaml", urikind.relative); Window. Show ();
How to say, or WP development code is relatively concise =
The above mentioned how to transfer values between pages in WP applications is also very convenient, but in WPF the situation is different.
There are several ways to pass values between Windows first:
1. Declare a global variable, that is App.xaml inside the declaration, in all forms can refer to application.current.properties["ArgumentName"];
2. The second is to expose a property on the target form and assign the value directly;
3. Finally, the parameter navigationservice.navigate is passed in the URI (window object,argument value)
4. Use the event response to pass the value.
The examples in Http://www.cnblogs.com/fdyang/archive/2013/03/25/2980451.html's blog are quite clear.
2. About binding.
Data binding in WP is generally based on the MVVM principle, that is, Model-view-view-model is to bind some of the control's values to some of the properties of your model, so that you can define your control based on the number of elements in your model, the attributes of the elements, This code has a high rate of reuse and is more efficient.
In my WP application I need to write datatemplate in my XAML before I can use the binding to connect my background to the front end. This is the data template I wrote:
<gridview itemssource="{Binding}"isitemclickenabled="True"ItemClick="Gridview_itemclick"> <GridView.ItemTemplate> <DataTemplate> <border borderbrush="Black"borderthickness="1"Width=" the"height=" the"> <textblock text="{Binding Coursename}"FontSize=" the"Foreground="Black"textwrapping="Wrap"texttrimming="characterellipsis"/> </Border> </DataTemplate> </GridView.ItemTemplate> </GridView>
First here the itemssource="{Binding}" should correspond to the code I wrote above:
datacontext="{Binding courseviewmodel, Relativesource={relativesource Self}}"
The Courseviewmodel here is my bound object, which is a collection container of instances of my custom class.
First, this is in the GridView definition border Embedded TextBlock template, meaning that each corresponding to a courseviewmodel element, will be here in the GridView add an embedded TextBlock border, Then TextBlock text="{Binding coursename}" means that the content of the TextBlock is set to the attribute coursename of the element corresponding to each element.
Public Static Observablecollection<courseinfomation> courseviewmodel { getreturn Fivedaycourses._courseviewmodel;} }
The Courseviewmodel of the above binding is as above.
And then, in the process of writing, I encountered a change of my properties in my Courseviewmodel, but the content in the control was not changed at the same time, and later I knew that the binding was only binding once when the control was initialized, to achieve the real-time refresh I needed, To implement the INotifyPropertyChanged interface for the target class, the code is as follows:
Public classcourseinfomation:inotifypropertychanged { Public intCourseID {Get;Set; } //Public string Coursename {get; set;} Private stringCoursename; Public stringCoursename {Get{returnCoursename;} Set { if(Value! = This. Coursename) {Coursename=value; Notifypropertychanged ("Coursename"); } } } Public stringTeacherName {Get;Set; } Public stringPlace {Get;Set; } PublicTimeSpan StartTime {Get;Set; } PublicTimeSpan EndTime {Get;Set; } Public EventPropertyChangedEventHandler propertychanged; Private voidNotifypropertychanged ([Callermembername]stringPropertyName ="") { if(PropertyChanged! =NULL) {propertychanged ( This,NewPropertyChangedEventArgs (PropertyName)); } } }
In my courseinfomation class, I can see that my coursename and other properties are a little different, which is what I set when coursename this property refreshes the binding when it changes, implementing the update effect.
The binding is still worth studying, but I'm just touching the fur.
This blog is probably so, in the binding of my WP app still have some questions about the JSON initialization model content, that is, to read the JSON file into the collection container, and my code to initialize the collection container function code calls between the logic problem, Causes my JSON file to write in, cannot read, the binding cannot, I will find out this logic question as soon as possible.
Go ahead! C#!
Tju_scs_c# Learning Notes (9)