2011年8月24日 星期三

XAML 2009

.NET Framework 4已經支援XAML 2009規範,但是目前的Visual Studio 2010 SP1與 Microsoft Expression Blend 4工具並不支援,目前你可以使用Loose XAML檔來撰寫支援XAML 2009語法的WPF程式。
XAML 2009 語言功能,可以參考 MSDN
底下介紹一個簡單範例,在過去使用XAML 2006時,若要使用CLR中的string型別,我們必需撰寫以下程式,引用clr-namespace:System命名空間
<StackPanel   
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
  <StackPanel.Resources>
        <sys:String x:Key="myData">WPF</sys:String>     </StackPanel.Resources>  
         <Label Content="{StaticResource myData}" ></Label>      
</StackPanel>
若是使用XAML 2009,則可改為如下,注意StackPanel引用了XAML 2009規範

  <StackPanel.Resources>
        <x:String x:Key="myData">WPF</x:String>     </StackPanel.Resources>  
         <Label Content="{StaticResource myData}" ></Label>      
</StackPanel>

沒有留言:

總網頁瀏覽量