can we have a control on brightness of the screen in wp7?

后端 未结 2 1076
我寻月下人不归
我寻月下人不归 2021-01-28 12:57

How to make the screen dim after few seconds and after a tap it should be bright.Is that possible ?

2条回答
  •  终归单人心
    2021-01-28 13:49

    I guess you could get creative with it - how about putting up a partially transparent control (maybe Background="#66000000") over the whole screen when you want to dim it, and on tap on that control it gets removed? That would give you the effect you're looking for without having to go into system internals. It really depends whether you want the controls on the page to be available for interaction while the screen is dimmed.

    So your Page.xaml would look like this...

    
    
        
        
            
                
                
            
    
            
            
                
                
            
    
            
            
                
                    
                    
                    
                    
                    
                    
                
            
    
            
    
        
    
    

    and in your code behind, something like this...

    public partial class MainPage : PhoneApplicationPage
    {
        DispatcherTimer dimmerTimer;
    
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            dimmerTimer = new DispatcherTimer();
            dimmerTimer.Tick += dimmerTimer_Tick;
            dimmerTimer.Interval = TimeSpan.FromSeconds(5);
            dimmerTimer.Start();
        }
    
        void dimmerTimer_Tick(object sender, EventArgs e)
        {
            DimDisplay();
        }
    
        void DimDisplay()
        {
            DimmerControl.Visibility = System.Windows.Visibility.Visible;
        }
        void UndimDisplay()
        {
            DimmerControl.Visibility = System.Windows.Visibility.Collapsed;
        }
    
        private void DimmerControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            UndimDisplay();
        }
    
        private void Input1Value_TextChanged(object sender, TextChangedEventArgs e)
        {
            UndimDisplay();
            dimmerTimer.Stop();
            dimmerTimer.Start();
        }
    }
    

    Note : This is a very simple proof of concept, and doesn't handle resetting the undimming timer when you do anything other than change the textbox values, but it will give you an idea. It also doesn't handle dimming the SIP, but there's not too much you can do about that other than explicitly removing focus from an input box.

提交回复
热议问题