Silverlight Archives - Mvvmlight Blog about accelerating the creation and development of MVVM applications Mon, 17 Jun 2024 09:25:21 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.4 https://www.mvvmlight.net/wp-content/uploads/2024/06/cropped-laptop-1626471_640-32x32.png Silverlight Archives - Mvvmlight 32 32 View Model class https://www.mvvmlight.net/view-model-class/ Mon, 13 Nov 2023 09:20:00 +0000 https://www.mvvmlight.net/?p=54 The representation model in the MVVM pattern encapsulates the logic of the representation and the data to be displayed.

The post View Model class appeared first on Mvvmlight.

]]>
The representation model in the MVVM pattern encapsulates the logic of the representation and the data to be displayed. It has no direct reference to the view or any knowledge of the view’s implementation or type. The view model implements properties and commands to which the view can bind data and notifies the view of any state changes via notification events. The properties and commands that the view model provides define the functionality relied upon by the UI, but the view defines how that functionality is to be represented.

Typically, the view model defines commands or actions that can be represented in the UI and invoked by the user. A typical example is when the view model provides a Submit command that allows the user to submit data to a web service or data repository. The view can present this command as a button so that the user can click it to submit the data. Typically, when a command becomes unavailable, its associated UI view becomes disabled. Commands provide a way to encapsulate user actions and cleanly separate them from their visual representation in the UI.

In summary, the view model has the following key characteristics:

  • The view model is a non-displayable class and does not inherit from any WPF or Silverlight base class. It encapsulates the view logic needed to support user actions in the application. The view model is testable independently of the view and model;
  • The view model usually does not directly reference the view. It implements properties and commands to which the view can bind data. It notifies the view of any state changes via notification events through the INotifyPropertyChanged and INotifyCollectionChanged interfaces;
  • The view model coordinates the view’s interaction with the model. It can transform or manipulate data so that it can be easily used by the view, and it can implement additional properties that may not be present in the model. It can also implement data validation through the IDataErrorInfo or INotifyDataErrorInfo interfaces;
  • The view model can define logical states that the view can visually present to the user.

The post View Model class appeared first on Mvvmlight.

]]>
Presentation class https://www.mvvmlight.net/presentation-class/ Tue, 07 Nov 2023 09:16:00 +0000 https://www.mvvmlight.net/?p=51 It is the responsibility of the view to determine the structure and appearance of what the user sees on the screen.

The post Presentation class appeared first on Mvvmlight.

]]>
It is the responsibility of the view to determine the structure and appearance of what the user sees on the screen. Ideally, the code-behind (background code) of a view contains only the constructor that calls the InitializeComponent method. In some cases, code-behind may contain UI logic code that implements visual behavior that is difficult or inefficient to express in XAML, such as complex animations, or when the code must directly control visual elements that are part of the view. It is not acceptable to put logic code that needs to be tested in a view. Typically, logic code in a code-behind view can be tested through UI automation.

In Silverlight and WPF, data binding expressions in a view are evaluated against its data context. In MVVM, the view model is set as the view’s data context. The view model implements properties and commands to which the view can be bound and notifies the view of any state changes through change notification events. There is usually a direct relationship between a view and its view model.

Typically, views are inherited from the Control or UserControl classes. However, in some cases, a view can be represented by a data template that defines the UI elements that will be used to visually represent the object. Using data templates, a developer can easily specify how a view model will be represented, or can change its default visual representation without changing the underlying object or its behavior directly.

To summarize, a view has the following key characteristics:

  • A view is a visual element such as a window, page, custom control, or data template. A view defines the controls, their layout and style;
  • A view references the view model through its DataContext property. Controls in a view are bound to the properties and commands of the view model;
  • A view can customize the data binding behavior between the view and the view model. For example, the view can use value converters to format the data to be shown in the UI, or use validation rules to provide additional validation of user input;
  • The view defines and handles the visual behavior of the UI, such as animations or transitions, which may be triggered by changes in the state of the view model or through user interaction with the UI;
  • A code-behind view can define UI logic to implement visual behavior that is difficult to express in XAML, or that requires direct references to specific UI controls defined in the view.

The post Presentation class appeared first on Mvvmlight.

]]>
Creating Web pages and applications with Microsoft Silverlight https://www.mvvmlight.net/creating-web-pages-and-applications-with-microsoft-silverlight/ Wed, 18 Oct 2023 08:54:00 +0000 https://www.mvvmlight.net/?p=48 Microsoft is one of the leaders in developing quality software. One of such products is Microsoft Silverlight.

The post Creating Web pages and applications with Microsoft Silverlight appeared first on Mvvmlight.

]]>
Microsoft is one of the leaders in developing quality software. One of such products is Microsoft Silverlight.

Despite the fact that this utility was released back in 2007, many users are still unaware of its capabilities. To get the most out of the Silverlight platform, it is important to understand its functionality, as well as to know how to install the program correctly.

Silverlight is a powerful software from Microsoft, which is analogous to Adobe Flash, and also has similar capabilities. It is available on Windows, Mac OS X and Symbian. However, Silverlight is not an ordinary program.

It is a platform for writing and running RIA web applications that are downloaded to the device, and can be dynamically updated at runtime by downloading data from the web. Silverlight is a technology used to develop multimedia software.

Microsoft Silverlight is an innovative technology that includes a module for the web browser. This module allows you to run applications with animation, vector or raster graphics, audio or video. The core component of the platform is the extensible XML-based markup language XALM. It allows you to add textual content to your application that is indexed by popular search engines such as Google.

Since the second version of Silverlight, the software has become a part of .NET technology, which allows applications to be developed in various programming languages such as C#, Object C++, and Python. Due to its cross-platform nature, all applications developed on the Silverlight platform function equally well on both PCs and phones.

Why it’s needed

To be able to view animation, streaming video, audio or interactive page content on websites, you need to install the appropriate plugin in your browser. There are several browsers that support Silverlight, but it is recommended to use the standard Internet Explorer. This technology works only on older versions of programs.

The utility is not only an analog of Adobe Flash, but also offers a much wider set of features:

  • cross-platform software, which allows it to be used on different operating systems;
  • indexing of written texts, which increases their visibility on the web;
  • ability to install the plugin as a browser extension, which simplifies its use;
  • full support for XAML with NET, which extends the possibilities of applications;
  • pixel shader effects that allow you to create unique visual effects;
  • lightweight software, low resource requirements, and easy installation make it accessible to a wide range of users;
  • free distribution of the software, which allows you to use it without additional costs;
  • possibility to transmit video stream to the server from the client, use of microphone with web-camera (from version 4), which simplifies creation of interactive applications;
  • support for 64-bit operating systems (since Silverlight 5 version), which improves software performance;
  • ability to create web applications or web pages, as well as a good toolkit for working with graphics;
  • high quality video playback without MediaPlayer;
  • playback speed control (since version 5).

The post Creating Web pages and applications with Microsoft Silverlight appeared first on Mvvmlight.

]]>
Silverlight templates https://www.mvvmlight.net/silverlight-templates/ Sun, 08 Oct 2023 08:50:00 +0000 https://www.mvvmlight.net/?p=45 Now, with the release of Silverlight 2, the number of applications based on this technology is increasing, but at the same time, certain growth challenges have emerged.

The post Silverlight templates appeared first on Mvvmlight.

]]>
Now, with the release of Silverlight 2, the number of applications based on this technology is increasing, but at the same time, certain growth challenges have emerged. The basic structure supported by the Silverlight 2 pattern involves tight integration of the user interface with the operational data. While this tight integration is useful for learning the technology, it has become an obstacle for testing, code optimization, and support.

The problem

At the heart of the problem is the tight coupling that results from mixing application tiers. When one tier is well aware of another tier performing a task, your application has a tight coupling. Take a simple data entry application that allows you to query homes for sale in a particular city. In a tightly bound application, you can define the query to perform the search in the UI button handler. When the schema or semantics of the search changes, both the data layer and the UI layer must be updated.

This leads to the problem of code complexity and quality. Every time the data layer changes, the application must be synchronized and tested to ensure that the changes are not major. If everything is tightly coupled, any move in one part of the application can cause ripple changes in the rest of the code. When creating something simple in Silverlight2, such as a video player or a mini menu application, tightly coupled application components are unlikely to be a problem. However, as the size of the project increases, the difficulties will be felt more and more.

The other side of the problem is unit testing. When an application is tightly coupled, only its functional (or UI) testing can be done. Again, this is not a problem in a small project, but as the size and complexity of the project increases, the ability to test application tiers separately becomes very important. Remember that unit testing is not just about verifying that a module works when it is used in the system, but that it continues to work in the system. Having unit tests for parts of the system adds confidence that when the system changes, problems will be discovered earlier in the process rather than later (which will happen with functional testing). Regression testing (e.g., running unit tests on the system on each build), which becomes key to ensuring that small changes added to the system do not cause cascading bugs.

Building an application by defining different tiers may seem to some developers like a case of over-development. The fact is that when you create an application with or without tiers, you are working with an n-tiered platform, and the application will have tiers. But without formal planning, you’ll end up with a very tightly bound system (and with the problems described above) or an application with a mass of unstructured code that will be a big problem to maintain.

It is easy to assume that creating an application with separate layers and tiers requires a lot of infrastructure to make it work well, but in fact simple tiering is quite easy to implement. (It is possible to design more complex application tiering using control inversion techniques, but that presents a different problem not covered in this article.)

Application tiering in Silverlight 2

Silverlight 2 does not require you to invent something new to define a way to tier your application. Several well-known patterns can be used for design.

There is a lot of talk now about the MVC (model-view-controller) pattern. In the MVC pattern, the model is the data, the view is the user interface, and the controller is the programmatic interface between the visualization, the model, and the user input. However, this pattern does not work well with declarative user interfaces such as Windows Presentation Foundation (WPF) or Silverlight because the XAML used by these technologies can define a specific interface between the input and the view (as data binding, triggers, and states can be declared in XAML).

“Model-View-Presenter-Presenter” (MVP) is another common pattern for tiering applications. In the MVP pattern, the presenter is responsible for setting up and managing state for the presentation. Like MVC, the MVP pattern is not well suited for the Silverlight 2 model because XAML may contain declarative data binding, triggers, and state management. What to do.

Fortunately for Silverlight 2, the WPF community has rallied around a pattern called the Model-View-View-Model (MVVM). This pattern is an adaptation of the MVC and MVP patterns, in which the view model provides the data model and behavior for the view, but allows the view to perform declarative binding to the view model. The view becomes a mixture of XAML and C# (like Silverlight 2 controls), the model represents the data available to the application, and the view model prepares the model for its binding to the view.

The post Silverlight templates appeared first on Mvvmlight.

]]>