2011年9月30日 星期五

Visual Studio 2011 Developer Preview

 

原本以為安裝很困難,找了一台Windows Server 2008 R2的電腦三個步驟就完成了,YA!

Snap1

Snap2

Snap3

2011年9月15日 星期四

Visual Studio 2011 Developer Preview 版與.NET 4.5

根據Jason Zander Blog 指出,Visual Studio 2011 Developer Preview 版與.NET 4.5開放下載了。目前只開放有 MSDN訂閱者下載,前往下載。沒有訂閱者,在星期五(16日) 就可下載。

2011年8月26日 星期五

Expression Blend(40)-改寫Control預設的Style (Button)

本範例使用WPF專案
若希望改寫 WPF 控制項的預設Style,以Button為例
  • 在window中加一個Button
  • 建立Style
image
  • Apply to all
image
  • 在Style編輯畫面,設B(粗體),I (斜體)與字型大小
image
  • 回到Window
image
  • 產生的XAML參考如下
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication3.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">
    <Window.Resources>
   
        <Style TargetType="{x:Type Button}">
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="FontStyle" Value="Italic"/>
            <Setter Property="FontSize" Value="16"/>
        </Style>
   
    </Window.Resources>
    <Grid x:Name="LayoutRoot">
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="72" Margin="24,24,0,0" VerticalAlignment="Top" Width="96"/>
    </Grid>
</Window>
  • 後續加Button到Window時,就會自動套用Style

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>

WPF- Loose XAML Files

在WPF中你可以只建立XAML檔案,但不要建立任何程式碼,稱之為Loose XAML檔案。Loose XAML可以直接以IE開啟(要裝.NET Framework 3以上版本)。若有包含程式碼,就不可用IE開啟,要改用Browser base的WPF應用程式。
Loose XAML Files特色
  • 是一個附檔名為 XAML檔案
  • 沒有相關聯的code-behind檔案
  • 不會編譯成一個應用程式
例如有一個Loose XAML Files,檔案內容如下:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
<StackPanel Margin="10" Width="150">
    <Label>Label</Label>
    <TextBox>TextBox</TextBox>
</StackPanel>
</Page>
這種類型的檔案,可以直接載入IE瀏覽器,在載入瀏覽器開啟後執行結果;
image
Loose XAML Files 限制
  • 根節點不可以是Window,可以是Page、Viewbox…等,例如
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
<StackPanel Margin="10" Width="150">
    <Label>Label</Label>
    <TextBox>TextBox</TextBox>
</StackPanel>
</Viewbox>
  • 根節點要定義必要的命名空間
  • Element不能有事件處理常式
  • 不是所有瀏覽器都支援

總網頁瀏覽量