新文章 网摘 文章 随笔 日记

wpf - 最大化 WPF 不会更新宽度?

    public partial class BigPicture : Window
    {
        private readonly Image _img;
        public BigPicture(Image img)
        {
            _img = img;
            InitializeComponent();
            WindowState = WindowState.Maximized;
            RefreshPic();
        }

        private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            RefreshPic();
        }

        private void RefreshPic()
        {
            ImgBigPic.Width = Math.Max(Width, ActualWidth) - 50;
            ImgBigPic.Height = Math.Max(Height, ActualHeight) - 50;
            ImgBigPic.Stretch = Stretch.Uniform;
            ImgBigPic.Source = _img.Source;
        }
    }

 

https://www.coder.work/article/6789618

posted @ 2023-07-11 10:02  岭南春  阅读(28)  评论(0)    收藏  举报