private void SetVisualElement(VisualElement oldElement, VisualElement newElement)
        {
            if (oldElement != null)
            {
                _context    = null;
                _nativeView = null;
                oldElement.PropertyChanged -= OnElementPropertyChanged;
            }

            if (newElement != null)
            {
                _nativeView = _renderer.ResolveViewFromRenderer();
                _context    = _nativeView.Context;
                newElement.PropertyChanged += OnElementPropertyChanged;
            }

            IMaterialVisualElement oldMaterialVisualElement;
            IMaterialVisualElement newMaterialVisualElement;

            switch (oldElement)
            {
            case IBackgroundElement oldBackgroundElement:
                oldMaterialVisualElement = oldBackgroundElement.Background;
                break;

            case IMaterialVisualElement oldMaterialElement:
                oldMaterialVisualElement = oldMaterialElement;
                break;

            default:
                oldMaterialVisualElement = oldElement == null ? null : BackgroundEffect.GetBackground(oldElement);
                break;
            }

            switch (newElement)
            {
            case IBackgroundElement newBackgroundElement:
                newMaterialVisualElement = newBackgroundElement.Background;
                break;

            case IMaterialVisualElement newMaterialElement:
                newMaterialVisualElement = newMaterialElement;
                break;

            default:
                newMaterialVisualElement = newElement == null ? null : BackgroundEffect.GetBackground(newElement);
                break;
            }

            _visualElement = newElement;

            SetBackgroundElement(oldMaterialVisualElement, newMaterialVisualElement);
        }
Exemple #2
0
        private void SetVisualElement(VisualElement oldElement, VisualElement newElement)
        {
            if (oldElement != null)
            {
                _context    = null;
                _nativeView = null;
                oldElement.PropertyChanged -= OnElementPropertyChanged;
            }

            if (newElement != null)
            {
                _nativeView = _renderer.ResolveViewFromRenderer();
                _context    = _nativeView.Context;
                newElement.PropertyChanged += OnElementPropertyChanged;
            }

            _visualElement = newElement;

            SetBackgroundElement(
                GetMaterialVisualElement(oldElement),
                GetMaterialVisualElement(newElement));
        }