FullScreenButton.xaml_1118

本文详细介绍了如何在WPF应用中实现全屏切换功能,并结合实例展示了全屏状态下的布局调整机制,包括窗口尺寸适应、滚动条自适应以及不同屏幕尺寸的显示效果优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interop;//为什么要引入这个命名空间呢?Pay Attention to it.

namespace ComputerDropDragControl
{
    public partial class FullScreenButton : UserControl
    {
        bool expand = false;
        public FullScreenButton(UIElement uc)
        {
            InitializeComponent();

            BackElement = uc;

            Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
        }


        #region <<控件事件>>

        #region <<全屏相关事件>>

        private void btnFullScreen_Click(object sender, RoutedEventArgs e)
        {
            FullScreen();
        }

        private void FullScreen()
        {
            Content contentObject = Application.Current.Host.Content;

            contentObject.IsFullScreen = !contentObject.IsFullScreen;
        }

        private void Content_FullScreenChanged(Object sender, EventArgs e)
        {
            Content contentObject = Application.Current.Host.Content;
            if (contentObject.IsFullScreen)
            {
                Content_Resized(sender, e, true);
                btnFullScreen.Background = new SolidColorBrush(Colors.Orange);
                btnFullScreen.Content = "退出全屏";
            }
            else
            {
                Content_Resized(sender, e, false);
                btnFullScreen.ClearValue(BackgroundProperty);
                btnFullScreen.Content = "全 屏";
            }
        }

        void Content_Resized(object sender, EventArgs e, bool fullScreen)
        {
            //double currentWidth = Application.Current.Host.Content.ActualWidth;
            double currentHeight = Application.Current.Host.Content.ActualHeight;
            //uniformScaleAmount = Math.Min((currentWidth / width), (currentHeight / height));
            //stackFather.Width = stackFather.ActualWidth * uniformScaleAmount;
            //stackFather.Height = stackFather.ActualHeight * uniformScaleAmount;
            //RootLayoutScaleTransform.ScaleX = uniformScaleAmount;
            //RootLayoutScaleTransform.ScaleY = uniformScaleAmount;
            //RootLayoutScaleTransformOne.ScaleX = uniformScaleAmount;
            //RootLayoutScaleTransformOne.ScaleY = uniformScaleAmount;
            ScrollViewer scrollOne = (ScrollViewer)BackElement;
            if (fullScreen)
            {
                scrollOne.Width = Application.Current.Host.Content.ActualWidth;
                scrollOne.Height = Application.Current.Host.Content.ActualHeight;
                //this.scrollOne.Height = 700;
            }
            else
            {
                //设置“最外层滚动条”信息
                double browseWidth = Application.Current.Host.Content.ActualWidth;//SilverLight控件所在浏览器确定的宽度
                double browseHeight = Application.Current.Host.Content.ActualHeight;
                scrollOne.Width = browseWidth - 400;
                scrollOne.Height = browseHeight - 200;
            }

        }
        #endregion

        #endregion

        public UIElement BackElement { get; set; }

        public double scrollWidth { get; set; }

    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值