Skip to content

Latest commit

 

History

History
89 lines (61 loc) · 3.95 KB

systembackdrop_ondefaultsystembackdropconfigurationchanged_1268525519.md

File metadata and controls

89 lines (61 loc) · 3.95 KB
-api-id -api-type
M:Microsoft.UI.Xaml.Media.SystemBackdrop.OnDefaultSystemBackdropConfigurationChanged(Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop,Microsoft.UI.Xaml.XamlRoot)
winrt method

Microsoft.UI.Xaml.Media.SystemBackdrop.OnDefaultSystemBackdropConfigurationChanged(Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop,Microsoft.UI.Xaml.XamlRoot)

-description

Override this method to be called when the object returned by GetDefaultSystemBackdropConfiguration changes. This is useful if you're using a custom SystemBackdropConfiguration.

-parameters

-param target

The target of the backdrop.

-param xamlRoot

The XAML root of the backdrop target.

-remarks

This method is useful when you implement a custom SystemBackdropConfiguration that incorporates some of the tracked property states but is different in some way from the default policy.

Instead of applying the default backdrop configuration obtained from GetDefaultSystemBackdropConfiguration (by passing it to SetSystemBackdropConfiguration), override OnDefaultSystemBackdropConfigurationChanged. When there is a change to the default policy (like when a user changes the system theme from Light to Dark), this method is called. In this method, create a new SystemBackdropConfiguration object and set it's properties as needed. Then pass the modified SystemBackdropConfiguration to SetSystemBackdropConfiguration.

-see-also

-examples

This example shows a custom system backdrop class that's implemented using MicaController. The OnDefaultSystemBackdropConfigurationChanged method is overridden, and in it the configuration Theme is set to always be light.

For example, if the system theme is changed from Light to Dark while the app is running, this method is called, and the backdrop theme is set back to Light rather than changing to Dark with the system theme.

<Window
    ... >
    <Window.SystemBackdrop>
        <local:MicaLightSystemBackdrop/>
    </Window.SystemBackdrop>

    <!-- XAML content -->

</Window>
public class MicaLightSystemBackdrop : SystemBackdrop
{
    MicaController micaController;

    protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot)
    {
        base.OnTargetConnected(connectedTarget, xamlRoot);

        if (micaController is not null)
        {
            throw new Exception("This controller cannot be shared");
        }

        micaController = new MicaController();
        //_ = GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot);

        micaController.AddSystemBackdropTarget(connectedTarget);
    }

    protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
    {
        base.OnTargetDisconnected(disconnectedTarget);

        micaController.RemoveSystemBackdropTarget(disconnectedTarget);
        micaController = null;
    }

    protected override void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
    {
        SystemBackdropConfiguration config = new SystemBackdropConfiguration();
        config.Theme = SystemBackdropTheme.Light;

        micaController.SetSystemBackdropConfiguration(config);
    }
}