As we know XAML allows us to define properties of elements using the attribute syntax. It means that,for example, if we want to specify the content/background colour of button control than we can specify it using attributes as shown below:
<Button Content="Attribute Style" Background = "Yellow"/>
However there might be a challenge using this syntax. Consider a scenario where we want to display a rectangle inside the button. In this case it would not be possible to define a rectangle in the content attribute.This will be due to string restrictions of attribute syntax. To overcome this kind of scenarios, XAML provides the Property elements.
The syntax of property element is . So now we can provide a child tag under the Button tag to define the rectangle inside the button. The code would be
<Rectangle Height="40" Width="40" Fill="Yellow"/>
Please note how beautifully the rectangle tag is given as child tag for Button.
The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of the Presentation Model design pattern introduced by Martin Fowler. Largely based on the Model-view-controller pattern (MVC), MVVM is targeted at modern UI development platforms (Windows Presentation Foundation and Silverlight) in which there is a UX developer who has different requirements than a more “traditional” developer (i.e. oriented toward business logic and back end development).
The Model is defined as in MVC; it is the data or business logic, completely UI independent, that stores the state and does the processing of the problem domain. The Model is written in code or is represented by pure data encoded in relational tables or XML.
A View is defined in XAML and should not have any logic in the code-behind. It binds to the view-model by only using data binding.
In simple examples, the View is data bound directly to the Model. Parts of the Model are simply displayed in the view by one-way data binding. Other parts of the model can be edited by directly binding controls two-way to the data.
The term means “Model of a View”, and can be thought of as abstraction of the view, but it also provides a specialization of the Model that the View can use for data-binding. In this latter role the ViewModel contains data-transformers that convert Model types into View types, and it contains Commands the View can use to interact with the Model.
The ViewModel exposes public properties, commands, and abstractions. The ViewModel has been likened to a conceptual state of the data as opposed to the real state of the data in the Model.
Tales from the Smart Client