In-depth Silverlight (I)-Silverlight Architecture

Source: Internet
Author: User

Silverlight consists of two parts: Core presentation framework (hereinafter referred to as core) and. NET Framework for Silverlight (hereinafter referred to.. net). The former is the core of the SL program written in C ++, and the latter is a programming framework written in C. Is the dll file in the SL folder after SL3 is installed:

Agcore is the dll file of Core presentation framework. In addition to Microsoft SL developers, no one can call the functions in this dll through normal methods. Other dll files are.. net.. NET Framework for Silverlight. You can find the dll file of each class in SL in MSDN, or you can use the reflection tool to view the metadata of these classes.

From MSDN, it is an official version of the SL architecture:

This figure shows the core and. net functions, and the two blue rounded rectangular boxes represent the core and. net functions. The information shown in this figure is accurate, but I think there are still some YY components. This image does not follow any standard format, so some parts are confusing. In my personal opinion, this figure has the following problems:

  1. It is very strange to put XAML in the middle of the two parts. The XAML parser is in the core part, and the two parts are not interacted through the XAML.
  2. In fact, the core part overlaps with the. NET part in the UI. The core part is responsible for not having to "bottom layer" as shown in the figure. Most of the layout work is completed in the core part.
  3. Similar to UI core, a considerable part of BCL is also responsible

After talking nonsense for a long time, let's go to the topic below. Those who have read the SL source code with the recycltor will surely be impressed. In the SL element inheritance tree, some very upper-level classes are very simple, such as UIElement, panel, Control, etc. This is because most of their functions are implemented in the core section. For most developers, the implementation of the. net part is in-depth enough, but I want to understand the interaction between the core part and the. NET part, which is more helpful for understanding the principle of SL.

All elements of SL (note that not all elements are objects) Adopt a design method called peer logic to avoid garbage collection and cross-language calls. NET Element objects correspond to a Native object, which can operate on each other and call each other. In a sense, they also represent the same UI element, but they are mutually referenced.

There are two very important classes in the MS. Internal namespace: FrameworkCallbacks and XcpImports. FrameworkCallbacks is called by the core part. and XcpImports is.. NET calls the core interface. These two classes do not have any non-static methods or fields. Their functions can basically be considered degraded into namespaces used to include functions. Because of the different features of. NET and dll, the structures of these two classes are also different.

Each callback in XcpImports corresponds to two functions, a Native function directly imported from the dll, and a simple encapsulation function that converts object reference into an Int pointer, for example, AddEventListener has the following two versions: (the Code comes from metadata and does not represent the real source code)

[DllImport("agcore", EntryPoint="AddEventListener", CharSet=CharSet.Unicode)]private static extern uint AddEventListenerNative(IntPtr element, uint property, ref CValue outval, bool handledEventsToo);
 
internal static unsafe void AddEventListener(INativeCoreTypeWrapper obj, DependencyProperty property, string eventName, bool handledEventsToo)

 

AddEventListener is only responsible for converting the object reference into a pointer that can be passed into AddEventListener.

FrameworkCallbacks is slightly complex. Taking UpdateResource as an example, FrameworkCallbacks contains a delegate type, a delegate instance, and a function.

Private static UpdateResourceDelegate_ UpdateResourceDelegate;

[Allowreversepinvokecballs, SecurityCritical] private static uintUpdateResource(IntPtr nativeDictionary, uint updateKind, [financialas (UnmanagedType. LPWStr)] string key, IntPtr nativeInValue, out IntPtr nativeOutValue)

[SecurityCritical] internal delegate uintUpdateResourceDelegate(IntPtr nativeFrameworkElement, uint updateKind, [financialas (UnmanagedType. LPWStr)] string key, IntPtr nativeInValue, out IntPtr nativeOutValue );

 

But interestingly, FrameworkCallbacks has some special cases. Not all functions are defined in FrameworkCallbacks, call back of some controls will be implemented as its own static method (it is estimated that many people will be depressed by such member functions when reading the source code), such

Private static ItemsControl_ClearVisualChildrenDelegate_ ItemsControl_ClearVisualChildren;

You can find the static method definition in ItemsControl.

 

That's all. Thank you for watching.

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.