前準備

  • VisualC#を起動して、新規プロジェクトでWPFプロジェクトを作ってください。プロジェクト名はLightPlayerにしました。

MainWindow.xamlをいったん削除する

  • App.xamlのStartupUri="MainWindow.xaml"を削除する
  • MainWindow.xamlを、MainWindow.xaml.csごと削除する

XAMLを書く

新しくウィンドウをMainWindowとして作成して、
MainWindow.xamlに以下のように書いてください。動作は全くしませんが、それなりの見た目ができます。
ビルドして起動まで確認できるはずです。

<Window x:Class="LightPlayer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="LightPlayer" Background="Black" SizeToContent="WidthAndHeight">
    <StackPanel>
        <Border CornerRadius="5" BorderThickness="2" Background="DarkGray"
                Margin="5" Padding="5">
            <StackPanel>
                <TextBlock>曲名</TextBlock>
                <TextBlock>アーティスト名</TextBlock>
            </StackPanel>
        </Border>
        <DockPanel Margin="5">
            <TextBlock Foreground="White" DockPanel.Dock="Right" VerticalAlignment="Center">0:15</TextBlock>
            <Slider MinWidth="200"/>
        </DockPanel>
        <StackPanel Orientation="Horizontal" Margin="5">
            <Button>←</Button>
            <Button>></Button>
            <Button>→</Button>
            <Button Margin="10,0">Open</Button>
            <Button Margin="10,0">Option</Button>
        </StackPanel>
    </StackPanel>
</Window>
※いったん削除したのは、フォルダを変更するためです

アプリ起動時にMainWindowを表示するように書き直す

	public partial class App : Application {
		protected override void OnStartup(StartupEventArgs e) {
			base.OnStartup(e);

			var window = new MainWindow();
			window.Show();
		}
	}

仕上がりイメージ


初心者向け解説(メモ程度)

MSDNとか見ればだいたいわかると思いますが、簡単に解説
  • SizeToContent→WindowのHeightとWidthを勝手に中身のサイズに合わせてくれるように設定
  • Border→今回は枠に丸みを持たせるために使用。曲名とアーティスト名を表示するための灰色の領域に相当
  • StackPanel→上か順番に(ボタンとかを)おいていくためのパネル。Orientationを指定すると左から右に置いていくことができる
  • DockPanel→ DockPanel.Dockで指定した上下左右のどれかから詰めてアイテムをおいていくパネル。最後の要素が残りの領域すべてを使用するのが特徴。
  • Margin="10,0"→左右のマージンを10、上下のマージンを0に指定。上下左右すべてを個別に指定したければMargin="10,8,6,4"のように指定できる

このページへのコメント

OuXh2p Im grateful for the article. Fantastic.

0
Posted by check it out 2014年01月23日(木) 18:24:35 返信

rOGppY <a href="http://hklxxcfgazdd.com/">hklxxcfgazdd</a>, [url=http://fmatposnqmhi.com/]fmatposnqmhi[/url], [link=http://ldbnjlpiixuf.com/]ldbnjlpiixuf[/link], http://fucxvtakovuh.com/

0
Posted by qqsqlrp 2013年11月14日(木) 16:46:44 返信

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

どなたでも編集できます