はじめてのAvalon

"Avalon" Quick Startから始めようとしたら、

1. Open Visual Studio .NET and select New and then Project from the File menu.
...

いきなり、VS.NETを要求されました。WinFX SDKテキストエディタで遊んでいる身としては、これはちょっとなので、VS.NETを使わないサンプルなどを。

打ち込むファイルは5つ。

  • App.xaml
  • App.xaml.cs (コードビハインド)
  • Page.xaml
  • Page.xaml.cs (コードビハインド)
  • Hello.csproj (プロジェクトファイル)

App.xaml

<NavigationApplication xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
                       xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
                       x:Class="App"
                       StartupUri="Page.xaml">

    <NavigationApplication.Resources>
    <Style>
      <NavigationWindow Width="400" Height="300"/>
    </Style>
    </NavigationApplication.Resources>
</NavigationApplication>

App.xaml.cs

using System.Windows.Navigation;

public partial class App : NavigationApplication
{
  public App () {
  }
}

Page.xaml

<Page xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
    xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
    x:Class="MyPage">
    <StackPanel>
    <TextBlock>Hello World</TextBlock>
    </StackPanel>
</Page>

Page.xaml.cs

using System.Windows.Controls;

public partial class MyPage : Page
{
}

Hello.csproj

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AssemblyName>Hello</AssemblyName>
    <TargetType>winexe</TargetType>
    <OutputPath>.\bin</OutputPath>
  </PropertyGroup>
  <ItemGroup>
    <ApplicationDefinition Include="App.xaml" />
    <Page Include="Page.xaml" />
    <Compile Include="App.xaml.cs">
      <DependentUpon>App.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="Page.xaml.cs">
      <DependentUpon>Page.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
    <Reference Include= "System"/>
    <Reference Include= "WindowsBase"/>
    <Reference Include= "PresentationCore"/>
    <Reference Include= "PresentationFramework"/>
    <Reference Include= "WindowsUIAutomation"/>
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
  <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets"/>
</Project>

ファイルを打ち込んだら、

> msbuild

で、ビルト。binディレクトリにhello.exeが生成されるので実行するとウィンドウにHello Worldの文字が表示されます。