XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
UTF-8
using Microsoft.UI;
using Microsoft.UI.Xaml.Media;
using SpaceEngineersBlueprintEditor.Interface.Services;
using System.Diagnostics.CodeAnalysis;
using XFEExtension.NetCore.WinUIHelper.Implements.Services;

namespace SpaceEngineersBlueprintEditor.Implements.Services;

/// <inheritdoc cref="IBackgroundImageService"/>
class BackgroundImageService : GlobalServiceBase, IBackgroundImageService
{
    private Page? _page;
    private Grid? _grid;

    [MemberNotNull(nameof(_page), nameof(_grid))]
    public void Initialize(Page page, Grid grid)
    {
        _page = page;
        _grid = grid;
    }

    public void ResetBackground()
    {
        if (_page is not null)
            _page.Background = new SolidColorBrush(Colors.Transparent);
        if (_grid is not null)
            _grid.Background = new SolidColorBrush(Colors.Transparent);
    }

    public void SetBackgroundImage(ImageSource imageSource)
    {
        if ((SystemProfile.Theme == ElementTheme.Default && Application.Current.RequestedTheme == ApplicationTheme.Dark) || SystemProfile.Theme == ElementTheme.Dark)
        {
            if (_page is not null)
                _page.Background = new ImageBrush
                {
                    ImageSource = imageSource
                };
            if (_grid is not null)
                _grid.Background = new AcrylicBrush
                {
                    TintLuminosityOpacity = 0,
                    TintColor = Colors.Transparent
                };
        }
    }
}