A template describes the overall appearance and visual look of the manage. For every manage there is a default template related to it which offers the appearance to that control. In WPF application, you may easily create your own templates when you need to customize the visual conduct and visible appearance of a manage. Connectivity among the logic and template can be finished through information binding.
In MVVM, there is another primary shape which is referred to as ViewModel first construction.
let’s take a look at our simple example once more wherein you will recognize how you may do view version first leveraging information templates, specifically implicit data templates. right here is the implementation of our StudentViewModel class.
You may see that the above View Model is unchanged. we will preserve with identical example from the preceding chapter. This View Model elegance simply exposes the students collection assets and populates it on construction. allow's visit the StudentView.xaml file, remove the existing implementation and define a information template in assets section.
Now upload a list field and records bind that list container to students assets as proven in the following code.
In the resource section, the Data Template has a key of students Template after which to really use that template, we need to apply the ItemTemplate assets of a ListBox. So now you may see that we instruct the listbox to go use that specific template for rendering out the ones students. Following is the complete implementation of StudentView.xaml file.
When the above code is compiled and done, you may see the following window, which includes one ListBox. each ListBoxItem includes the student class object facts which are displayed on TextBlock and text boxes.
To make this an implicit template, we want to put off the ItemTemplate assets from a list box and upload a DataType property in our template definition as proven inside the following code.
In DataTemplate, the x:kind markup extension is very crucial which is sort of a form of operator in XAML. So, basically we need to point to the student data type that is in MVVMDemo.version namespace. Following is the updated whole XAML file.
When you run this application again, you may still get the equal rendering of the students with information template because it's automatically mapping the type of the item being rendered by locating the right DataTemplate.
We suggest you to execute the above example in a step-by-step technique for better understanding.
MVVM Related Interview Questions
|C#. NET Interview Questions||. NET Interview Questions|
|Adv Java Interview Questions||Android Interview Questions|
|Graphic Design Interview Questions||LINQ Interview Questions|
|Web Developer Guide Interview Questions||Apache Cassandra Interview Questions|
|Windows Presentation Foundation(WPF) Interview Questions||Advanced C# Interview Questions|
|XAML Interview Questions||Blue Prism Interview Questions|
|Windows Forms Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.