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

后端 未结 2 1069
我寻月下人不归
我寻月下人不归 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:29

    For now, there is no way to control programmatically the brightness of the screen.

    0 讨论(0)
  • 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...

    <phone:PhoneApplicationPage 
    x:Class="ScreenDimmer.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    
        <!--LayoutRoot is the root grid where all page content is placed-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <!--TitlePanel contains the name of the application and page title-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="   {StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style=" {StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
    
            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <StackPanel Name="ControlStacker">
                    <TextBlock Text="My input 1" />
                    <TextBox Name="Input1Value" TextChanged="Input1Value_TextChanged" />
                    <TextBlock Text="My input 2" />
                    <TextBox Name="Input2Value" TextChanged="Input1Value_TextChanged"  />
                    <TextBlock Text="My input 3" />
                    <TextBox Name="Input3Value" TextChanged="Input1Value_TextChanged"  />
                </StackPanel>
            </Grid>
    
            <Canvas Grid.RowSpan="2" Margin="0" Height="800" Width="480"  Background="#66000000" Name="DimmerControl" MouseLeftButtonUp="DimmerControl_MouseLeftButtonUp" Visibility="Collapsed" />
    
        </Grid>
    </phone:PhoneApplicationPage>
    

    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.

    0 讨论(0)
提交回复
热议问题