こんな感じ
左からバーがスライドイン表示するよ。
ソースはここ
仕組み
WPFのWindow.Width
の値を大きくした時、Windowは右方向に伸びる。
バーをMainWindowとは別のWindowにして、Width
を勢いよく増やしていけば、実用性はともかく、これはもうスライドインと言ってもいいのではなかろうか。
MenuWindow.xaml.cs
// メインウィンドウ側から呼んでもらう、メニューバー表示用のメソッド
public async void ShowSlideWindow(double left, double top, double ownerWidth)
{
this.Top = top;
this.Left = left;
this.Show();
// スライドイン表示
for (int i = 1; i < 15; i++)
{
var newValue = this.Width + 30 * (i - 0.7);
if (newValue <= ownerWidth)
{
this.Width = newValue;
}
else
{
break;
}
await Task.Delay(1);
}
this.Width = ownerWidth;
}
本題とはあまり関係ありませんが、メニューバー以外の部分をクリックした時に、バーが消えてくれる動きが好きなので、WindowのDeactivatedイベントでClose()
しています。
MenuWindow.xaml.cs
private void Window_Deactivated(object sender, EventArgs e)
{
this.Close();
}