Jack's profileTechnology changes. Comm...PhotosBlogListsMore Tools Help

Blog


    June 16

    对前面的posts的补充

    要在Windows XP SP2/Windows Server 2003 SP1上运行WPF的应用请先安装WinFX Runtime,Windows Vista就不用下了,可以直接体验。请至M$站点下载,谢谢。
    相关下载(包括WinFX Runtime,Windows SDK)可在以下链接找到:http://msdn.microsoft.com/windowsvista/downloads/products/getthebeta/

    关于WPF(Windows Presentation Foundation),XAML (三)

    来一段稍复杂的
    <DockPanel     
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <TextBlock Background="LightBlue"
                  DockPanel.Dock="Top">Some Text</TextBlock>
      <TextBlock DockPanel.Dock="Bottom"
                  Background="LightYellow">Some text at the bottom of the page.</TextBlock>
      <TextBlock DockPanel.Dock="Left"
                  Background="Lavender">Some More Text</TextBlock>
      <DockPanel Background="Bisque">
        <StackPanel DockPanel.Dock="Top">
          <Button HorizontalAlignment="Left" 
                  Height="30px"
                  Width="100px"
                  Margin="10,10,10,10">Button1</Button>
          <Button HorizontalAlignment="Left"
                  Height="30px"
                  Width="100px"
                  Margin="10,10,10,10">Button2</Button>
        </StackPanel>
        <TextBlock Background="LightGreen">Some Text Below the Buttons</TextBlock>
      </DockPanel>
    </DockPanel>
    效果如图:(点击看大图)
     

    关于WPF(Windows Presentation Foundation),XAML (二)

    恩,前面忘记说了,WPF不仅仅可以用来搞Windows App,也可以用来搞Web App,也就是基于浏览器的(废话,不是基于浏览器的怎么叫Web App,SB!)你甚至可以让你的Windows App和Web App共用代码!
     
    光说无用,现在看段XAML代码:
    <StackPanel
      xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml">
      <Button HorizontalAlignment="Left"
              Width="100"
              Margin="10,10,10,10">Button 1</Button>        
      <Button HorizontalAlignment="Left"
              Width="100"
              Margin="10,10,10,10">Button 2</Button>
      <Button HorizontalAlignment="Left"
              Width="100"
              Margin="10,10,10,10">Button 3</Button>   
    </StackPanel>
     如图:(点击看大图,想自己动手的需要到M$站上去下Windows SDK。图中的XAML Cruncher工具可以到http://www.netfx3.com里的Gallery里的tools下面去找。Windows SDK自己也带有一个类似的XMLPad。这两个工具都是用来即时显示代码的效果)
     

    关于WPF(Windows Presentation Foundation),XAML (一)

    恩,WPF,洋文是Windows Presentation Framework,大陆汉语也就是Windows表现层基础(注:非官方译法,为本人杜撰),台湾汉语不知道这个怎么港的。WPF是.Net Framework 3.0(formly WinFX)
    的一块,其他几块还有WCF, WWF, WCS。WPF设计的主要目的就是为了可以像做网页那样做Windows GUI应用程序,也就是把界面表现和工作逻辑尽量分离。所以,这里就要引入一个XAML的概念,看上去是不是很像XML,没错,就是M$扩展自XML, 增加的A是Application,语法格式什么都跟XML一样。XAML为实现你的应用的界面提供了一个弹性且强大的方式。(1)使用XML tags——元素们被描述在一个叫做.xaml类型的源文件里通过XML tags,然后呢tag名字都有关联一个相同的Window Presentation Foundation类。i.e.:<Button>元素对应Button对象。(2)Functions like procedural code——任何东西有能用XAML搞得,你就可以通过过程性的代码用对象模型搞。尽管对象模型有些能力XAML没有,XAML is usually much easier to localize than the equivalent procedual code.(3)遵循严格形式(well-formed)的XML规则——XMAL是基于XML的;因此,侬的代码必须遵守严格形式的XML的通常规则。

    XAML 的元素:

    XAML consists of a collection of elements that contain the following functional categories.

    • Root elements function as the root element for a page. Some root elements can only be used as root elements, and others can be used elsewhere. The most commonly used root elements are the panel elements and Page, which enables you to declaratively control several of the properties of the window that contains the page.

    • Panel elements, such as DockPanel, handle page layout and act as containers for elements, such as controls or other panels.

    • Control elements, such as ListBox, handle user interaction.

    • Document elements, such as Paragraph, handle document presentation.

    • Shape elements, such as Ellipse, handle vector graphic shapes.

    更多关于XAML元素的信息:

    • Have attributes that correspond to class properties—Most elements have one or more attributes that correspond to properties in the associated class. They are typically used for specifying how an element appears.

    • Raise a variety of events—Elements raise a variety of events, typically as a result of a user action, such as a mouse Click event. Each event is represented in XAML by an attribute. To attach an event handler to the event, assign the handler name to the event attribute. You typically implement the handler in the code-behind file for the page.

    • Have multiple child events—Many elements have one or more child elements, which vary according to a particular element.

    • Can contain text labels—For elements that contain text, you usually specify the text by placing it between beginning and ending tags. For example, <Button>Some Button</Button> creates a button labeled "Some Button." Because this control has an associated property, you can also set the content by using procedural code.