示例#1
0
        private void ApplyDynamicBackground([CanBeNull] string filename, double opacity = 0.5)
        {
            ActionExtension.InvokeInMainThreadAsync(() => {
                try {
                    if (filename == null)
                    {
                        DisposeHelper.Dispose(ref _dynamicBackground);
                        if (FancyBackgroundManager.Instance.Enabled)
                        {
                            FancyBackgroundManager.Instance.Recreate(this);
                        }
                        else
                        {
                            ClearValue(BackgroundContentProperty);
                        }
                    }
                    else
                    {
                        var animatedBackground = Regex.IsMatch(filename, @"\.(?:avi|flv|gif|m(?:4[pv]|kv|ov|p[4g])|og[vg]|qt|webm|wmv)$",
                                                               RegexOptions.IgnoreCase) ?
                                                 filename : null;
                        var staticBackground = animatedBackground == null ? filename : Regex.Replace(filename, @"\.\w+$", @".jpg");

                        _dynamicBackground?.Dispose();
                        BackgroundContent = _dynamicBackground = new DynamicBackground {
                            Animated = animatedBackground,
                            Static   = staticBackground,
                            Opacity  = opacity
                        };
                    }
                } catch (Exception e) {
                    Logging.Error(e);
                }
            });
        }