Search code examples
c#uwpscreen-brightness

BrightnessOverride.IsSupportedChanged is not triggered when I switch the monitors


I have a question about how this UWP API: BrightnessOverride.IsSupportedChanged works. Currently here is my setup:

  1. I have a HP laptop, and I can use BrightnessOverride to change the brightness on it. If I try to get IsSupported, it's returning true.
  2. I also have a docking station for this laptop, and it has two monitors. When on the docking station, the IsSupported is false because Windows cannot change the brightness in this case.

The problem I have is, when I start my app, and then remove the laptop from the docking station, BrightnessOverride.IsSupportedChanged is not called. If I try to get IsSupported, it's still true. I have to restart my app to make it return true again. Same thing happens if I switch from docking mode to laptop mode, IsSupported will stay as false and the event never get called.

I feel like when the device is changed, I probably need to call GetForCurrentView() again to get the new view to override, but how do I do that if the event is not called?

The document here is not providing any example: https://learn.microsoft.com/en-us/uwp/api/windows.graphics.display.brightnessoverride.issupportedchanged

To reproduce this issue, I setup a simple UWP test app and I add this in the MainPage constructor:

b = BrightnessOverride.GetForCurrentView();
b.IsSupportedChanged += B_IsSupportedChanged;

The callback:

private void B_IsSupportedChanged(BrightnessOverride sender, object args)
{
    TextBlock1.Text = "Is changed";
}

And in a button click function I print out the IsSupported value.


Solution

  • feel like when the device is changed, I probably need to call GetForCurrentView() again to get the new view to override, but how do I do that if the event is not called?

    For your merriment, you could use ProjectionDisplayAvailableChanged event to detect monitor changed. It occurs when a projector or other secondary display becomes available or unavailable.

    ProjectionManager.ProjectionDisplayAvailableChanged += ProjectionManager_ProjectionDisplayAvailableChanged;
    
    private void ProjectionManager_ProjectionDisplayAvailableChanged(object sender, object e)
    {
       //call GetForCurrentView method again
    }