|
6 | 6 | [TemplatePart(Name = RenderBorder, Type = typeof(Border))] |
7 | 7 | public sealed partial class ImageFrame : Control, IDisposable |
8 | 8 | { |
| 9 | + private Color _shadowColor = Colors.Transparent; |
| 10 | + |
9 | 11 | #region Enums |
10 | 12 |
|
11 | 13 | private enum ImageEngineState |
@@ -81,6 +83,43 @@ private enum ImageEngineState |
81 | 83 |
|
82 | 84 | #region Dependency Properties |
83 | 85 |
|
| 86 | + public bool UseAutoShadowColor |
| 87 | + { |
| 88 | + get { return (bool)GetValue(UseAutoShadowColorProperty); } |
| 89 | + set { SetValue(UseAutoShadowColorProperty, value); } |
| 90 | + } |
| 91 | + |
| 92 | + public static readonly DependencyProperty UseAutoShadowColorProperty = |
| 93 | + DependencyProperty.Register(nameof(UseAutoShadowColor), typeof(bool), typeof(ImageFrame), new PropertyMetadata(false, OnUseAutoShadowColor)); |
| 94 | + |
| 95 | + private async static void OnUseAutoShadowColor(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 96 | + { |
| 97 | + var ctl = (ImageFrame)d; |
| 98 | + if (ctl != null && ctl.DisplayShadow) |
| 99 | + { |
| 100 | + ctl.UpdateShadowColor(); |
| 101 | + ctl.InvalidateArrange(); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + private async void UpdateShadowColor() |
| 106 | + { |
| 107 | + if (UseAutoShadowColor) |
| 108 | + { |
| 109 | + var uri = GetUriFromSource(); |
| 110 | + if (uri != null) |
| 111 | + { |
| 112 | + var device = CanvasDevice.GetSharedDevice(); |
| 113 | + _shadowColor = await ColorHelperEx.GetImageEdgeColorWithWin2DAsync(device, uri); |
| 114 | + } |
| 115 | + } |
| 116 | + else |
| 117 | + { |
| 118 | + _shadowColor = ShadowColor; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + |
84 | 123 | #region AlignX |
85 | 124 |
|
86 | 125 | /// <summary> |
@@ -570,6 +609,7 @@ private void OnShadowColorChanged() |
570 | 609 | // Refresh Layout if shadow is displayed |
571 | 610 | if (DisplayShadow) |
572 | 611 | { |
| 612 | + UpdateShadowColor(); |
573 | 613 | InvalidateArrange(); |
574 | 614 | } |
575 | 615 | } |
@@ -807,6 +847,8 @@ private void OnSourceChanged() |
807 | 847 |
|
808 | 848 | // If the ImageFrame is properly initialized, then we can schedule this Uri |
809 | 849 | // to be loaded next. |
| 850 | + |
| 851 | + UpdateShadowColor(); |
810 | 852 | ScheduleNextLoad(); |
811 | 853 | } |
812 | 854 |
|
@@ -914,17 +956,17 @@ private void OnTransitionDurationChanged(TimeSpan newTransitionDuration) |
914 | 956 | /// TransitionMode Dependency Property |
915 | 957 | /// </summary> |
916 | 958 | public static readonly DependencyProperty TransitionModeProperty = |
917 | | - DependencyProperty.Register(nameof(TransitionMode), typeof(TransitionModeType), typeof(ImageFrame), |
918 | | - new PropertyMetadata(TransitionModeType.FadeIn)); |
| 959 | + DependencyProperty.Register(nameof(TransitionMode), typeof(ImageFrameTransitionMode), typeof(ImageFrame), |
| 960 | + new PropertyMetadata(ImageFrameTransitionMode.FadeIn)); |
919 | 961 |
|
920 | 962 | /// <summary> |
921 | 963 | /// Gets or sets the TransitionMode property. This dependency property |
922 | 964 | /// indicates the type of transition animation to employ for displaying |
923 | 965 | /// an image after it has been loaded. |
924 | 966 | /// </summary> |
925 | | - public TransitionModeType TransitionMode |
| 967 | + public ImageFrameTransitionMode TransitionMode |
926 | 968 | { |
927 | | - get => (TransitionModeType)GetValue(TransitionModeProperty); |
| 969 | + get => (ImageFrameTransitionMode)GetValue(TransitionModeProperty); |
928 | 970 | set => SetValue(TransitionModeProperty, value); |
929 | 971 | } |
930 | 972 |
|
@@ -1235,7 +1277,7 @@ protected override Size ArrangeOverride(Size finalSize) |
1235 | 1277 | : (_shadow ?? (_shadow = _compositor.CreateDropShadow())); |
1236 | 1278 |
|
1237 | 1279 | shadow.BlurRadius = ShadowBlurRadius.ToSingle(); |
1238 | | - shadow.Color = ShadowColor; |
| 1280 | + shadow.Color = _shadowColor; |
1239 | 1281 | shadow.Offset = new Vector3(ShadowOffsetX.ToSingle(), ShadowOffsetY.ToSingle(), 0); |
1240 | 1282 | shadow.Opacity = ShadowOpacity.ToSingle(); |
1241 | 1283 | shadow.Mask = _layerEffectBrush.GetSourceParameter("mask"); |
@@ -1833,35 +1875,35 @@ private void StartTransition(bool isFirstLoad) |
1833 | 1875 | switch (TransitionMode) |
1834 | 1876 | { |
1835 | 1877 | // New content fades into view |
1836 | | - case TransitionModeType.FadeIn: |
| 1878 | + case ImageFrameTransitionMode.FadeIn: |
1837 | 1879 | nextContent.StartAnimation("Opacity", _fadeInAnimation); |
1838 | 1880 | break; |
1839 | 1881 | // New content slides from right to left |
1840 | | - case TransitionModeType.SlideLeft: |
| 1882 | + case ImageFrameTransitionMode.SlideLeft: |
1841 | 1883 | nextContent.Offset = new Vector3(nextContent.Size.X, 0, 0); |
1842 | 1884 | nextContent.Opacity = 1; |
1843 | 1885 | nextContent.StartAnimation("Offset", _offsetAnimation); |
1844 | 1886 | break; |
1845 | 1887 | // New content slides from left to right |
1846 | | - case TransitionModeType.SlideRight: |
| 1888 | + case ImageFrameTransitionMode.SlideRight: |
1847 | 1889 | nextContent.Offset = new Vector3(-nextContent.Size.X, 0, 0); |
1848 | 1890 | nextContent.Opacity = 1; |
1849 | 1891 | nextContent.StartAnimation("Offset", _offsetAnimation); |
1850 | 1892 | break; |
1851 | 1893 | // New content slides up from bottom to top |
1852 | | - case TransitionModeType.SlideUp: |
| 1894 | + case ImageFrameTransitionMode.SlideUp: |
1853 | 1895 | nextContent.Offset = new Vector3(0, nextContent.Size.Y, 0); |
1854 | 1896 | nextContent.Opacity = 1; |
1855 | 1897 | nextContent.StartAnimation("Offset", _offsetAnimation); |
1856 | 1898 | break; |
1857 | 1899 | // New content slides down from top to bottom |
1858 | | - case TransitionModeType.SlideDown: |
| 1900 | + case ImageFrameTransitionMode.SlideDown: |
1859 | 1901 | nextContent.Offset = new Vector3(0, -nextContent.Size.Y, 0); |
1860 | 1902 | nextContent.Opacity = 1; |
1861 | 1903 | nextContent.StartAnimation("Offset", _offsetAnimation); |
1862 | 1904 | break; |
1863 | 1905 | // New content zooms into view |
1864 | | - case TransitionModeType.ZoomIn: |
| 1906 | + case ImageFrameTransitionMode.ZoomIn: |
1865 | 1907 | nextContent.Scale = new Vector3(MinScaleFactor, MinScaleFactor, 1); |
1866 | 1908 | nextContent.Offset = new Vector3(nextContent.Size.X * (1 - MinScaleFactor) / 2f, |
1867 | 1909 | nextContent.Size.Y * (1 - MinScaleFactor) / 2f, 0); |
@@ -1890,7 +1932,7 @@ private void DisplayPlaceHolder() |
1890 | 1932 | { |
1891 | 1933 | _placeholderBackgroundVisual.Opacity = 1; |
1892 | 1934 | } |
1893 | | - else if (TransitionMode == TransitionModeType.FadeIn) |
| 1935 | + else if (TransitionMode == ImageFrameTransitionMode.FadeIn) |
1894 | 1936 | { |
1895 | 1937 | _placeholderBackgroundVisual.StartAnimation("Opacity", _fadeInAnimation); |
1896 | 1938 | } |
|
0 commit comments