What is XAML?
XAML (pronounced "Zamel," which rhymes with "camel"), or Extensible Application Markup Language, is Microsoft's new XML-based declarative up language for building application in the next generation of Windows, code-named "Longhorn". XAML allows the developer to control the layout of application interfaces including text, graphics, buttons, and the entire collection of .NET user interface controls. Each XAML tag corresponds directly to a .NET Framework class. So creating a new button, for example, is as simple as using a <Button> tag in your XAML file. The tag will then instantiate a Button object using the default constructor then allow you to set properties on the button, such as text label, size, etc. Events and the associated "code behind" handler is specified in the XAML as attributes as well. In Longhorn, code can be either inlined in your XAML file or place in the code behind file, much like ASP.NET. By using XAML as the presentation layer and your favorite .NET language as the logic and event handling layer, this model allows you to build powerful application that can be easily updated and modified without having to cross the line between presentation and logic. That is, the interface can be completely changed without rewriting your logic and event-handling code. XAML is a very powerful system, and Longhorn, Microsoft's next generation Windows, is one of the most exciting things to ever come from Microsoft. XAML has one "catch"—it is currently only part of Avalon, which is the presentation layer of Longhorn. Many capabilities of XAML are tied directly to Longhorn, but on the other hand, many of the concepts could, in theory, be applied to today's .NET Framework on today's Windows platforms. What is Xamlon?
Xamlon (pronounced "Zamelon," which rhymes with "avalon"), is a XAML runtime library for the .NET Framework 1.1. Xamlon is not a 100% XAML compatible library, it was not designed to be, but rather uses the same syntax as XAML to provide the same power and capabilities as XAML but for building "Windows.Forms"-based applications instead. Simply put: 
"Xamlon is XAML for Windows.Forms" There are several key benefits of using Xamlon today: Application development becomes much more simple and efficient. Xalmon provides a very clean separation between presentation and application logic. 
Xamlon application run on all of today's .NET Framework 1.1 Windows operating systems: Windows 98, ME, NT, 2000, XP, and Server 2003. 
Xamlon provides a much simpler migration path to Microsoft's next-generation presentation layer in Longhorn, XAML. 
Xamlon is not a XAML port or 100% compatibility library, but rather a subset of XAML that allows for the development of Windows Forms application using the same XML up syntax as XAML. Page Links:
What is XAML?
What is Xamlon?
How does Xamlon work?
Are there examples online?
How do I get Xamlon?
How does Xamlon work?
Unlike Longhorn's XAML, Xamlon does not convert your XAML up to C# (or Visual Basic.NET). Instead, Xamlon interprets your XAML at run-time very efficiently to dynamically create your application interface(s). Your logic and event handling code is specified as "Class Behind" files, much like ASP.NET's or XAML's "Code Behind" attribute. The class that handles the event handling can be written in any .NET language. By interpreting your XAML documents during runtime, this affords your great flexibility in how you deploy your application. You can embed your .xaml files as resources, leave them intact on disk to load at runtime, dynamically load them from the internet, and so on. Because Xamlon interprets the code at run-time, logic code (i.e. C# / VB.NET) cannot be inserted into the XAML up, but rather needs to live entirely in the class behind file. This ultimately leads to cleaner, easier to read XAML. Page Links:
What is XAML?
What is Xamlon?
How does Xamlon work?
Are there examples online?
How do I get Xamlon?
Are there examples online?
Xamlon ships with several examples showing various features and capabilities of the library. We will continually be adding new examples to future releases. You can also find the latest set of examples in the support section of this web site. Page Links:
What is XAML?
What is Xamlon?
How does Xamlon work?
Are there examples online?
How do I get Xamlon?
How do I get Xamlon?
Xamlon is currently in beta. Proceed to the download section to download the latest version. Closer to the release date, Xamlon pricing will be determined. Xamlon is licensed per developer and has no runtime licensing fees. 

解决方案 »

  1.   

    As you will see in the following sections, "XAML" is just as easy to use.        
    <?xml version="1.0" standalone="yes"?>
    <Window>
        <Button>Hello World</Button>
    </Window>
          
    Creating a User Interface with "XAML"
    "XAML" is the primary way to create a UI in the "Longhorn" programming model because it provides a way to separate UI definition from logic and enables you to integrate code within or behind up. The ability to mix code with up is important because XML does not support flow control well. In "Longhorn", applications can be written entirely in "XAML" and deployed "loose" like HTML but if you need imperative code to react to user interaction you must mix up with code and compile the application.As stated previously, "XAML" enables you to create a UI without using code. You can create quite elaborate documents entirely in up using controls, text, images, shapes and so forth. The following "XAML" example shows how little up is necessary to create a button.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    <Button>Click Me!</Button>
    </Canvas>      
    However, if you want some event to occur when users click the button you must use code behind or within the up to handle the click event. The following example shows a code block inside an "XAML" file. When the button is clicked its background becomes red.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    <Button Click="Button_Click">Click Me!</Button>

    <def:Code>
      <![CDATA[
      
        void Button_Click(object sender, ClickEventArgs e)
        {
            btn1.Background = Brushes.Red;
        }
      ]]>
    </def:Code>
    </Canvas>      
    You can also place event handling code in a file separate from the "XAML" file, called a "code-behind" file. The following example creates the same application as the previous example but the code is in two files—an "XAML" file and a C# code-behind file."XAML" file         
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    <Button Click="Button_Click">Click Me!</Button>
    </Canvas>      
    C# code-behind file 
            
    using System;
    using MSAvalon.Windows;
    using MSAvalon.Windows.Controls;
    using MSAvalon.Windows.Media;namespace Button
    {
    public class Default : Panel
    {
        // Event handler
    void Button_Click(object sender, MSAvalon.Windows.Controls.ClickEventArgs e)
             {
              btn1.Background = MSAvalon.Windows.Media.Brushes.Red;
             }
    }
    }      
    Creating a Basic "XAML" File
    This section explains the basic structure of "XAML" files—the steps you need to complete before you actually start adding UI elements. "XAML" files are XML files with an .xaml extension. "XAML" has a set of rules to map classes into tags, attributes into properties and events, and XML namespaces to common language runtime namespaces; for example, "XAML" tags map directly to Microsoft&reg; .NET classes.The Root Element
    Like all .xml files, .xaml files must have one root tag, but a mandatory root tag is not defined. Generally a panel, such as a DockPanel, FlowPanel or Canvas, is the root element. In the following example, the root element is a Canvas. 
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    ...
    ...
    </Canvas>  
      

  2.   

    An "XAML" parser needs a way to determine which assemblies and namespaces should be searched to find a tag name. "XAML" uses xmlns, an attribute, to find the mapping. For example, the following example shows the root element of a typical "XAML" file. Notice that the assemblies and namespaces that contain the elements (tags) used by the application are specified by: xmlns="http://schemas.microsoft.com/2003/xaml".         
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    ...
    ...
    </Canvas>       
    Adding Code
    Most "Longhorn" applications consist of both "XAML" and code, such as Microsoft Visual Basic&reg; .NET or C#. As mentioned previously, the code can be added in the "XAML" file or in a separate code-behind file.In order to use many of the tags that enable you to add code to a page, a definition file is necessary. Notice that you use the xmlns attribute to specify the definition file. The following example shows how you specify the definition file by adding a new namespace to the root element, xmlns:def="Definition".        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    ...
    ...
    </Canvas>      
    <def:Code> is an element for containing programming code. If you do not want to create a separate code-behind file you can put your code inside the "XAML" file. The following example illustrates inline C# code. Notice that the code is inside a <def:Code> tag and that the code must be surrounded by <CDATA[...]]> so the up parser will not try to parse the code.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
       <Button ID="button1" Click="Clicked">Click Me!</Button>
       <def:Code>        
            <![CDATA void Clicked(object sender, ClickEventArgs args)
    {
    button1.Content = "Hello World";
    }
            ]]>
       </def:Code>
    </Canvas>      
    Adding UI Elements
    The previous section discussed common elements used in "XAML" files. This section explains UI elements such as controls that you add to an "XAML" file to provide fully functioning applications.Base Classes
    Underneath "XAML" is a collection of class objects that correspond to up elements; however, some classes cannot be mapped to elements. Abstract classes, like ButtonBase, are used for inheritance and do not have "XAML" up tags.FrameworkElement is the base UI class of the "Longhorn" presentation framework. FrameworkElement extends from UIElement. UIElement is the base class for frameworks building on the "Longhorn" presentation core. UIElement provides the ability to render on the screen, interact with a user, and define the level of interoperability between multiple frameworks. Most developers will use FrameworkElement instead of UIElement because FrameworkElement contains a rich set of UI elements. When designing UI, developers should use shape, panel, decorator, or control classes which all derive from FrameworkElement.Most interaction between an "XAML" application and an end user is accomplished through control classes. For example, the TextBox class enables users to enter text input and receive output. The following example shows the complete code needed to create a text box that allows you to enter and delete text. Notice that you simply use the <TextBox> tag to create a text box object.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition"><TextBox>This is a Text Box</TextBox></Canvas>       
    "XAML" Properties
    "XAML" properties enable you to add features to element tags. For example, the following up creates a button with red italicized text and a blue background.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    <Button Background="Blue" Foreground="White" FontStyle="Italic">This is a button</Button>
    </Canvas>      
    Properties are often inherited from abstract classes; for example, in the previous code example, the Background property is not a property on the Button class but is inherited from the abstract Control class. See Button for a list of properties that can be used with a button.Compound Properties
    Properties can be set directly as simple attributes, as in the following example.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    <Button Background="Blue">This is a button</Button>
    </Canvas>      
    Properties can also be defined as compound properties. The syntax for such properties is <Class.Property>. Using the compound property syntax, it is possible to use items other than objects as the property value, such as animations or data binds.The following example shows a compound property that uses the <Class.Property> syntax.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    <Button>
    <Button.Background>Blue</Button.Background>
    </Button>
    </Canvas>      
    The following example defines the button's background with an object, in this case a gradient.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
    <Button>
    <Button.Background>
           <HorizontalGradient StartColor="Blue" EndColor="White"/>
    </Button.Background>
    </Button>
    </Canvas>      
    Events
    "XAML" creates UI elements such as buttons, text boxes, shapes, and so forth but it cannot be used to handle events. For example, if you have a button on a page that displays "Hello World" when clicked, "XAML" can create and display the button and hook the event to an event handler but it cannot be used to write the event handler. You must write an event handler in a language such as Visual Basic .NET or C#. The following example shows the "XAML" that creates the button and the C# code that displays the text.        
    <Canvas ID="root"
    xmlns="http://schemas.microsoft.com/2003/xaml"
    xmlns:def="Definition">
       <Button ID="button1" Click="Clicked">Click Me!</Button>
          <def:Code>        
            <![CDATA void Clicked(object target, ClickEventArgs args)
    {
    button1.Content = "Hello World";
    }
            ]]>
          </def:Code>
    </Canvas>