LoginSignup
1
0

More than 3 years have passed since last update.

[WPF]左からスライドインするメニューバー

Posted at

こんな感じ

左からバーがスライドイン表示するよ。

slidein2.gif

ソースはここ

仕組み

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();
        }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0