Share via


SystemBackdrop.OnDefaultSystemBackdropConfigurationChanged Method

Definition

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

protected:
 virtual void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop ^ target, XamlRoot ^ xamlRoot) = OnDefaultSystemBackdropConfigurationChanged;
void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop const& target, XamlRoot const& xamlRoot);
protected virtual void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot);
function onDefaultSystemBackdropConfigurationChanged(target, xamlRoot)
Protected Overridable Sub OnDefaultSystemBackdropConfigurationChanged (target As ICompositionSupportsSystemBackdrop, xamlRoot As XamlRoot)

Parameters

target
ICompositionSupportsSystemBackdrop

The target of the backdrop.

xamlRoot
XamlRoot

The XAML root of the backdrop target.

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

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.

Applies to