WPF Learning Notes

Source: Internet
Author: User
Tags command line mscorlib xmlns

Microsoft defines XAML as a "simple", "generic", "declarative" programming language. This means that we will see it in more places (such as Silverlight), and it is obviously more logical to handle than its original version of XML, which is a language based on XML and that follows XML structure rules. If you want, we can completely throw out XAML to write WPF programs. It's just that it's kind of like using Notepad to develop a. NET program that's not fun to use. The definition pattern of XAML makes it possible for non-programmers to portray the UI in an "understandable" way, and we are already familiar with it, such as WebForm, or the Delphi Form I've been thinking about all the time, but I've forgotten the Object Pascal.

<Window x:Class="Learn.WPF.Window1"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Title="Window1">
 <Grid>
 </Grid>
</Window>

This is a very simple XAML that defines a blank WPF form (Window). XAML corresponds to. NET code, except that the process is accomplished by a particular XAML compiler and run-time interpreter. When the interpreter processes the above code, the equivalent:

New Window1 {Title = "Window1"};

From here we can understand the difference between the two, the advantage of using XAML is that you can see the final presentation in the design phase, obviously this is what art needs. You can enter "Xamlpad.exe" from the VS command line, so you can see the intuitive effect.

As a "language" applied to the. NET platform, XAML also supports many of the concepts we know and need.

1. Namespace

XAML maps the following. NET Namespace to "Http://schemas.microsoft.com/winfx/2006/xaml/presentation" by default:

System.Windows

System.Windows.Automation

System.Windows.Controls

System.Windows.Controls.Primitives

System.Windows.Data

System.Windows.Documents

System.Windows.Forms.Integration

System.Windows.Ink

System.Windows.Input

System.Windows.Media

System.Windows.Media.Animation

System.Windows.Media.Effects

System.Windows.Media.Imaging

System.Windows.Media.Media3D

System.Windows.Media.TextFormatting

System.Windows.Navigation

System.Windows.Shapes

In addition to this primary namespace, which contains most of the required types of WPF, there is a XAML-specific namespace (System.Windows.Markup)-"Http://schemas.microsoft.com/winfx/2006/xaml". The syntax for using a Non-default namespace is somewhat similar to C # Namespace Alias, and we need to add a prefix, such as "X" in the example below.

<Window x:Class="Learn.WPF.Window1"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Title="Window1">
 <Grid>
  <TextBox x:Name="txtUsername" Background="{x:Null}"></TextBox>
 </Grid>
</Window>

We can also introduce CLR Namespace.

<collections:Hashtable
 xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
 xmlns:sys="clr-namespace:System;assembly=mscorlib">
 <sys:Int32 x:Key="key1">1</sys:Int32>
</collections:Hashtable>

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.