我们可以控制wp7屏幕的亮度吗?

时间:2011-12-07 10:30:17

标签: c# windows-phone-7

如何让屏幕在几秒钟后变暗,点击后它应该很亮。这可能吗?

2 个答案:

答案 0 :(得分:1)

目前,无法以编程方式控制屏幕的亮度。

答案 1 :(得分:1)

我想你可以发挥它的创造力 - 当你想要调暗它时,如何在整个屏幕上放置一个部分透明的控件(可能是Background =“#66000000”),然后点击该控件就会被删除?这将为您提供您正在寻找的效果,而无需进入系统内部。这取决于您是否希望在屏幕变暗时页面上的控件可用于交互。

所以你的Page.xaml看起来像这样......

<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>

并且在您的代码中,类似这样......

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

注意:这是一个非常简单的概念验证,除了更改文本框值之外的其他任何操作都不会处理重置失调计时器,但它会给你一个想法。它也没有处理SIP的变暗,但除了明确地从输入框中删除焦点之外,你没有太多可以做的事情。