Esempio n. 1
0
        // Handle attached property changed to automatically target and untarget UIElements and Brushes.
        private static void OnIsTargetChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            var isAdding = (bool)e.NewValue;

            if (isAdding)
            {
                if (obj is UIElement)
                {
                    XamlLight.AddTargetElement(GetIdStatic(), obj as UIElement);
                }
                else if (obj is Brush)
                {
                    XamlLight.AddTargetBrush(GetIdStatic(), obj as Brush);
                }
            }
            else
            {
                if (obj is UIElement)
                {
                    XamlLight.RemoveTargetElement(GetIdStatic(), obj as UIElement);
                }
                else if (obj is Brush)
                {
                    XamlLight.RemoveTargetBrush(GetIdStatic(), obj as Brush);
                }
            }
        }
Esempio n. 2
0
        protected override void OnConnected()
        {
            if (DesignMode.DesignModeEnabled)
            {
                return;
            }
            compositor = ElementCompositionPreview.GetElementVisual(Window.Current.Content as UIElement).Compositor;
            var compositeEffect = new CompositeEffect()
            {
                Mode = CanvasComposite.Add
            };

            compositeEffect.Sources.Add(new BorderEffect()
            {
                Source  = new CompositionEffectSourceParameter("backdrop"),
                ExtendX = CanvasEdgeBehavior.Clamp,
                ExtendY = CanvasEdgeBehavior.Clamp
            });
            compositeEffect.Sources.Add(new BorderEffect()
            {
                Source  = new CompositionEffectSourceParameter("color"),
                ExtendX = CanvasEdgeBehavior.Clamp,
                ExtendY = CanvasEdgeBehavior.Clamp
            });

            var Brush = compositor.CreateEffectFactory(compositeEffect).CreateBrush();

            Brush.SetSourceParameter("backdrop", compositor.CreateBackdropBrush());
            Brush.SetSourceParameter("color", compositor.CreateColorBrush(Color));
            CompositionBrush = Brush;

            XamlLight.AddTargetBrush(Lights.RevealAmbientLight.GetIdStatic(), this);
            XamlLight.AddTargetBrush(Lights.RevealBorderSpotLight.GetIdStatic(), this);
        }
Esempio n. 3
0
 protected override void OnDisconnected(UIElement oldElement)
 {
     // 这一句是对应的,Add了之后就要Remove
     XamlLight.RemoveTargetElement(GetId(), oldElement);
     // 释放资源
     CompositionLight.Dispose();
     CompositionLight = null;
 }
Esempio n. 4
0
        protected override void OnConnected(UIElement newElement)
        {
            (newElement as FrameworkElement).SizeChanged += XamlPointLight_SizeChanged;
            // 创建灯光
            var        compositor = Window.Current.Compositor;
            PointLight light      = compositor.CreatePointLight();

            // 设置灯光参数
            light.Color      = ((SolidColorBrush)Color).Color;
            CompositionLight = light;
            // 这一句很重要
            XamlLight.AddTargetElement(GetId(), newElement);
        }
Esempio n. 5
0
        // Handle attached property changed to automatically target and untarget UIElements and Brushes.
        private static void OnTargetIdPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            string oldId = e.OldValue as string;
            string newId = e.NewValue as string;

            string[] oldIds = null;
            if (!string.IsNullOrEmpty(oldId))
            {
                oldIds = oldId.Split(',');
            }
            else
            {
                oldIds = new string[0];
            }
            string[] newIds = null;
            if (!string.IsNullOrEmpty(newId))
            {
                newIds = newId.Split(',');
            }
            else
            {
                newIds = new string[0];
            }

            List <string> added   = new List <string>();
            List <string> removed = new List <string>();

            foreach (var id in newIds)
            {
                if (!oldIds.Contains(id))
                {
                    added.Add(id);
                }
            }
            foreach (var id in oldIds)
            {
                if (!newIds.Contains(id))
                {
                    removed.Add(id);
                }
            }

            foreach (var id in added)
            {
                if (obj is UIElement)
                {
                    XamlLight.AddTargetElement(GetIdStatic(id), obj as UIElement);
                }
                else if (obj is Brush)
                {
                    XamlLight.AddTargetBrush(GetIdStatic(id), obj as Brush);
                }
            }
            foreach (var id in removed)
            {
                if (obj is UIElement)
                {
                    XamlLight.RemoveTargetElement(GetIdStatic(id), obj as UIElement);
                }
                else if (obj is Brush)
                {
                    XamlLight.RemoveTargetBrush(GetIdStatic(id), obj as Brush);
                }
            }
        }
Esempio n. 6
0
 protected override void OnDisconnected()
 {
     base.OnDisconnected();
     XamlLight.RemoveTargetBrush(Lights.RevealAmbientLight.GetIdStatic(), this);
     XamlLight.RemoveTargetBrush(Lights.RevealBorderSpotLight.GetIdStatic(), this);
 }