示例#1
0
        private void LoadImages()
        {
            string worktimeimgpath = string.IsNullOrEmpty(config.options.Style.DataWindowWorkTimeImagePath) ? "pack://application:,,,/ProjectEye;component/Resources/web_developer.png" : config.options.Style.DataWindowWorkTimeImagePath;
            string resttimeimgpath = string.IsNullOrEmpty(config.options.Style.DataWindowRestTimeImagePath) ? "pack://application:,,,/ProjectEye;component/Resources/coffee_lover.png" : config.options.Style.DataWindowRestTimeImagePath;
            string skipimgpath     = string.IsNullOrEmpty(config.options.Style.DataWindowSkipImagePath) ? "pack://application:,,,/ProjectEye;component/Resources/office_work_.png" : config.options.Style.DataWindowSkipImagePath;

            Data.WorktimeImageSource = BitmapImager.Load(worktimeimgpath);
            Data.ResttimeImageSource = BitmapImager.Load(resttimeimgpath);
            Data.SkipImageSource     = BitmapImager.Load(skipimgpath);
        }
        private void CreateUI()
        {
            var    container  = new Grid();
            string uiFilePath = $"UI\\{config.options.Style.Theme.ThemeName}_{ScreenName}.json";
            var    data       = JsonConvert.DeserializeObject <UIDesignModel>(FileHelper.Read(uiFilePath));

            if (data == null)
            {
                data = theme.GetCreateDefaultTipWindowUI(config.options.Style.Theme.ThemeName, ScreenName);

                FileHelper.Write(uiFilePath, JsonConvert.SerializeObject(data));
            }
            var containerBG = new Border();

            containerBG.Width  = Double.NaN;
            containerBG.Height = Double.NaN;
            containerBG.SetValue(Grid.ZIndexProperty, -1);
            containerBG.Background = data.ContainerAttr.Background;
            containerBG.Opacity    = data.ContainerAttr.Opacity;
            container.Children.Add(containerBG);
            foreach (var element in data.Elements)
            {
                var ttf = new TranslateTransform()
                {
                    X = element.X,
                    Y = element.Y
                };
                switch (element.Type)
                {
                case Project1.UI.Controls.Enums.DesignItemType.Text:
                    var textElement = CreateTextElemenet(element);
                    textElement.RenderTransform = ttf;
                    container.Children.Add(textElement);
                    break;

                case Project1.UI.Controls.Enums.DesignItemType.Button:
                    var buttonElement = CreateButtonElement(element);
                    buttonElement.RenderTransform = ttf;
                    container.Children.Add(buttonElement);
                    break;

                case Project1.UI.Controls.Enums.DesignItemType.Image:
                    var imageElement = new Image();
                    imageElement.HorizontalAlignment = HorizontalAlignment.Left;
                    imageElement.VerticalAlignment   = VerticalAlignment.Top;
                    imageElement.RenderTransform     = ttf;
                    imageElement.Width   = element.Width;
                    imageElement.Height  = element.Height;
                    imageElement.Opacity = element.Opacity;
                    imageElement.Stretch = Stretch.Fill;
                    try
                    {
                        //imageElement.Source = new BitmapImage(new Uri(element.Image, UriKind.RelativeOrAbsolute));
                        imageElement.Source = BitmapImager.Load(element.Image);
                    }
                    catch
                    {
                        imageElement.Source = BitmapImager.Load("pack://application:,,,/Project1.UI;component/Assets/Images/sunglasses.png");
                        //imageElement.Source = new BitmapImage(new Uri("pack://application:,,,/Project1.UI;component/Assets/Images/sunglasses.png", UriKind.RelativeOrAbsolute));
                    }
                    container.Children.Add(imageElement);
                    break;
                }
            }



            WindowInstance.Content = container;
        }
示例#3
0
 /// <summary>
 /// 设置通知图标路径
 /// </summary>
 /// <param name="filePath">文件绝对路径</param>
 public void SetIcon(string filePath)
 {
     //        Icon = new BitmapImage(
     //new Uri(filePath));
     Icon = BitmapImager.Load(filePath);
 }
示例#4
0
        private void CreateWindowOpenAnimation()
        {
            CreateTransformGroup();

            Opacity = 0;
            openWindowStoryboard = new Storyboard();
            var duration = TimeSpan.FromSeconds(1);

            if (WindowAnimationType == AnimationType.RightBottomScale)
            {
                //位移动画


                var easingFunction = new BackEase()
                {
                    EasingMode = EasingMode.EaseInOut
                };
                DoubleAnimation translateXAnimation = new DoubleAnimation();
                translateXAnimation.From     = ScreenArea.Width;
                translateXAnimation.To       = Left;
                translateXAnimation.Duration = duration;
                //BackEase,QuarticEase
                translateXAnimation.EasingFunction = easingFunction;
                Storyboard.SetTarget(translateXAnimation, this);
                Storyboard.SetTargetProperty(translateXAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
                DoubleAnimation translateYAnimation = new DoubleAnimation();
                translateYAnimation.From           = ScreenArea.Height;
                translateYAnimation.To             = Top;
                translateYAnimation.Duration       = duration;
                translateYAnimation.EasingFunction = easingFunction;
                Storyboard.SetTarget(translateYAnimation, this);
                Storyboard.SetTargetProperty(translateYAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"));

                //缩放动画
                var scaleEasingFunction = new QuarticEase()
                {
                    EasingMode = EasingMode.EaseInOut
                };
                DoubleAnimation scaleXAnimation = new DoubleAnimation();
                scaleXAnimation.From     = 0;
                scaleXAnimation.To       = 1;
                scaleXAnimation.Duration = duration;
                //BackEase,QuarticEase
                scaleXAnimation.EasingFunction = scaleEasingFunction;
                Storyboard.SetTarget(scaleXAnimation, this);
                Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)"));
                DoubleAnimation scaleYAnimation = new DoubleAnimation();
                scaleYAnimation.From           = 0;
                scaleYAnimation.To             = 1;
                scaleYAnimation.Duration       = duration;
                scaleYAnimation.EasingFunction = scaleEasingFunction;
                Storyboard.SetTarget(scaleYAnimation, this);
                Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleY)"));



                openWindowStoryboard.Children.Add(translateXAnimation);
                openWindowStoryboard.Children.Add(translateYAnimation);
                openWindowStoryboard.Children.Add(scaleXAnimation);
                openWindowStoryboard.Children.Add(scaleYAnimation);
            }
            else if (WindowAnimationType == AnimationType.Opacity)
            {
                DoubleAnimation opacityAnimation = new DoubleAnimation();
                opacityAnimation.From           = 0;
                opacityAnimation.To             = 1;
                opacityAnimation.Duration       = duration;
                opacityAnimation.EasingFunction = new CubicEase()
                {
                    EasingMode = EasingMode.EaseInOut
                };
                Storyboard.SetTarget(opacityAnimation, this);
                Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty));
                openWindowStoryboard.Children.Add(opacityAnimation);
            }
            else if (WindowAnimationType == AnimationType.Cool)
            {
                //RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);

                //  保存布局
                var ui = Content as Grid;
                Content = null;
                //  创建新的容器
                var container = new Grid();
                container.RenderTransform       = new TransformGroup();
                container.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);

                (container.RenderTransform as TransformGroup).Children.Add(new ScaleTransform()
                {
                    ScaleX = 1,
                    ScaleY = 1
                });
                container.Children.Add(ui);
                Content = container;

                //Opacity = 1;

                var icon = new System.Windows.Controls.Image();
                icon.Source = BitmapImager.Load($"pack://application:,,,/ProjectEye;component/Resources/sunglasses.ico");
                icon.HorizontalAlignment   = HorizontalAlignment.Left;
                icon.VerticalAlignment     = VerticalAlignment.Top;
                icon.RenderTransform       = new TransformGroup();
                icon.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
                var scaleTF = new ScaleTransform()
                {
                    ScaleX = 1,
                    ScaleY = 1
                };
                var ttf = new TranslateTransform()
                {
                    X = ScreenArea.Width / 2 - 150,
                    Y = -300
                };
                (icon.RenderTransform as TransformGroup).Children.Add(scaleTF);
                (icon.RenderTransform as TransformGroup).Children.Add(ttf);
                icon.IsHitTestVisible = false;
                icon.Width            = 300;
                icon.Height           = 300;
                container.Children.Add(icon);



                //位移动画
                var easingFunction = new BackEase()
                {
                    EasingMode = EasingMode.EaseInOut
                };

                DoubleAnimation translateYAnimation = new DoubleAnimation();
                translateYAnimation.From           = -300;
                translateYAnimation.To             = ScreenArea.Height / 2 - 150;
                translateYAnimation.Duration       = TimeSpan.FromSeconds(1);
                translateYAnimation.EasingFunction = easingFunction;
                //translateYAnimation.AutoReverse = true;
                Storyboard.SetTarget(translateYAnimation, icon);
                Storyboard.SetTargetProperty(translateYAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)"));

                //  logo放大缩小动画
                DoubleAnimationUsingKeyFrames scaleAnimation = new DoubleAnimationUsingKeyFrames();
                scaleAnimation.KeyFrames.Add(
                    new LinearDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
                scaleAnimation.KeyFrames.Add(
                    new LinearDoubleKeyFrame(2, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.8))));
                scaleAnimation.KeyFrames.Add(
                    new LinearDoubleKeyFrame(15, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));

                Storyboard.SetTarget(scaleAnimation, icon);
                DoubleAnimationUsingKeyFrames scaleAnimation2 = new DoubleAnimationUsingKeyFrames();
                scaleAnimation2.KeyFrames.Add(
                    new LinearDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
                scaleAnimation2.KeyFrames.Add(
                    new LinearDoubleKeyFrame(2, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.8))));
                scaleAnimation2.KeyFrames.Add(
                    new LinearDoubleKeyFrame(15, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));

                Storyboard.SetTarget(scaleAnimation, icon);
                Storyboard.SetTarget(scaleAnimation2, icon);

                Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"));
                Storyboard.SetTargetProperty(scaleAnimation2, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"));

                //  logo透明动画

                DoubleAnimationUsingKeyFrames iconOpacityAnimation = new DoubleAnimationUsingKeyFrames();
                iconOpacityAnimation.KeyFrames.Add(
                    new LinearDoubleKeyFrame(.8, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.8))));
                iconOpacityAnimation.KeyFrames.Add(
                    new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1.2))));
                Storyboard.SetTarget(iconOpacityAnimation, icon);
                Storyboard.SetTargetProperty(iconOpacityAnimation, new PropertyPath(OpacityProperty));


                //  ui透明动画
                DoubleAnimation opacityAnimation2 = new DoubleAnimation();
                opacityAnimation2.From = 0;

                opacityAnimation2.To             = 1;
                opacityAnimation2.Duration       = TimeSpan.FromSeconds(1.5);
                opacityAnimation2.EasingFunction = new CubicEase()
                {
                    EasingMode = EasingMode.EaseInOut
                };
                Storyboard.SetTarget(opacityAnimation2, ui);
                Storyboard.SetTargetProperty(opacityAnimation2, new PropertyPath(OpacityProperty));



                //  窗口透明动画
                DoubleAnimation windowOpacityAnimation = new DoubleAnimation();
                windowOpacityAnimation.From           = 0;
                windowOpacityAnimation.To             = 1;
                windowOpacityAnimation.Duration       = TimeSpan.FromSeconds(1.5);
                windowOpacityAnimation.EasingFunction = new CubicEase()
                {
                    EasingMode = EasingMode.EaseInOut
                };
                Storyboard.SetTarget(windowOpacityAnimation, this);
                Storyboard.SetTargetProperty(windowOpacityAnimation, new PropertyPath(OpacityProperty));

                openWindowStoryboard.Children.Add(translateYAnimation);

                openWindowStoryboard.Children.Add(opacityAnimation2);
                openWindowStoryboard.Children.Add(iconOpacityAnimation);
                openWindowStoryboard.Children.Add(scaleAnimation);
                openWindowStoryboard.Children.Add(scaleAnimation2);
                openWindowStoryboard.Children.Add(windowOpacityAnimation);
            }
        }