Пример #1
0
        private static void UpdateShadowDepth(UIElement element, ShadowDepth shadowDepth, bool loaded = false)
        {
            var adornerLayer = AdornerLayer.GetAdornerLayer(element);

            if (adornerLayer == null)
            {
                if (!loaded)
                {
                    element.Dispatcher.InvokeAsync(() => UpdateShadowDepth(element, shadowDepth, true), DispatcherPriority.Loaded);
                }

                return;
            }

            var topMostAdornerLayer = adornerLayer;
            //while (topMostAdornerLayer != null)
            //{
            //    topMostAdornerLayer = AdornerLayer.GetAdornerLayer(topMostAdornerLayer);
            //}

            var shadowAdorner = GetShadowAdorner(element);

            if (shadowDepth == ShadowDepth.Depth0)
            {
                if (shadowAdorner != null)
                {
                    SetShadowAdorner(element, null);
                    topMostAdornerLayer.Remove(shadowAdorner);
                }
            }
            else
            {
                if (shadowAdorner == null)
                {
                    shadowAdorner = new ShadowAdorner(element);
                    MaterialDesignThemes.Wpf.ShadowAssist.SetShadowDepth(shadowAdorner.Shadow, shadowDepth);
                    topMostAdornerLayer.Add(shadowAdorner);
                    SetShadowAdorner(element, shadowAdorner);
                }
                else
                {
                    MaterialDesignThemes.Wpf.ShadowAssist.SetShadowDepth(shadowAdorner.Shadow, shadowDepth);
                }
            }
        }
Пример #2
0
 public static void SetShadowAdorner(DependencyObject obj, ShadowAdorner value)
 {
     obj.SetValue(ShadowAdornerProperty, value);
 }