Example #1
0
        /// <summary>
        /// Method for initializing all properties and fields
        /// </summary>
        private void Init()
        {
            mainWindow = Window.GetWindow(this);
            mainWindow.StateChanged += MainWindow_StateChanged;
            var helper = new WindowInteropHelper(mainWindow);

            if (helper.Handle != null)
            {
                var source = HwndSource.FromHwnd(helper.Handle);
                if (source != null)
                {
                    source.AddHook(HwndMessageHook);
                }
            }

            _shift = ActualWidth / Convert.ToDouble(DataCount);


            _minValue = MinValue;
            _maxValue = MaxValue;

            Canvas.SetTop(Dot, 0);
            Canvas.SetLeft(Dot, 0);

            Canvas.SetTop(ActualValueText, 0);
            Canvas.SetLeft(ActualValueText, 0);

            _bottom        = ActualHeight * 0.8;
            _bottomOfChart = ActualHeight;
            _top           = ActualHeight * 0.6;
            _range         = _maxValue - _minValue;

            _maxRenderingPoint = (_shift * Convert.ToDouble(DataCount)) * 0.8;

            _lastHeight = ActualHeight;
            _lastWidth  = ActualWidth;

            Dot.Fill = DotColor;

            //Render by software, issue with dropshadow performance
            HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
            HwndTarget hwndTarget = hwndSource.CompositionTarget;

            hwndTarget.RenderMode = RenderMode.SoftwareOnly;

            Dot.Effect = new DropShadowEffect
            {
                Color       = ((SolidColorBrush)DotColor).Color,
                Direction   = 45,
                ShadowDepth = 0,
                Opacity     = 1,
            };

            Storyboard      storyboard1    = new Storyboard();
            DoubleAnimation colorAnimation = new DoubleAnimation()
            {
                From           = 10,
                To             = 0,
                RepeatBehavior = RepeatBehavior.Forever,
                AutoReverse    = true
            };

            colorAnimation.BeginTime = TimeSpan.FromSeconds(1);
            Storyboard.SetTargetProperty(colorAnimation, new PropertyPath("Effect.BlurRadius"));
            storyboard1.Children.Add(colorAnimation);

            storyboard1.Begin(Dot);


            ActualValueText.Effect = new DropShadowEffect
            {
                Color       = ((SolidColorBrush)Foreground).Color,
                Direction   = 45,
                ShadowDepth = 1,
                Opacity     = 0.2,
                BlurRadius  = 2
            };

            Label_MinY.Margin = new Thickness(0, 0, 0, 0);

            XAxis.Stroke = AxisColor;
            YAxis.Stroke = AxisColor;

            _mainLine.StrokeThickness = 3;
            _mainLine.Stroke          = LineColor;
            _mainLine.Fill            = ChunkColor;

            Border_YAxisLegend.Height = CanvasMain.ActualHeight;

            _gridBackground = new GridBackground();
            MakeGridBackground();
            SetGridBackground();

            Label_MaxY.Visibility = Visibility.Hidden;
            Label_MinY.Visibility = Visibility.Hidden;
            Label_MaxX.Visibility = Visibility.Hidden;
            Label_MinX.Visibility = Visibility.Hidden;


            DataSource.CollectionChanged += DataSource_CollectionChanged;
        }
Example #2
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            if (Owner != null)
            {
                //Owner.ForceCursor = true;

                Owner.Cursor = Cursors.Arrow;
                this.Cursor  = Cursors.Arrow;
            }

#if NET40
            this.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);
            this.SetValue(TextOptions.TextRenderingModeProperty, TextRenderingMode.Auto);
            this.SetValue(TextOptions.TextHintingModeProperty, TextHintingMode.Fixed);
#endif //NET40

            Console.WriteLine(@"Popup WpfSoftwareRender => " + Tobi.Common.Settings.Default.WpfSoftwareRender);

            if (Tobi.Common.Settings.Default.WpfSoftwareRender)
            {
                var hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                if (hwndSource != null)
                {
                    HwndTarget hwndTarget = hwndSource.CompositionTarget;
                    hwndTarget.RenderMode = RenderMode.SoftwareOnly;
                }
            }

            //0 => No graphics hardware acceleration available for the application on the device.
            //1 => Partial graphics hardware acceleration available on the video card. This corresponds to a DirectX version that is greater than or equal to 7.0 and less than 9.0.
            //2 => A rendering tier value of 2 means that most of the graphics features of WPF should use hardware acceleration provided the necessary system resources have not been exhausted. This corresponds to a DirectX version that is greater than or equal to 9.0.
            int renderingTier = (RenderCapability.Tier >> 16);

            Console.WriteLine(@"Popup RenderCapability.Tier => " + renderingTier);

            try
            {
                //Uri iconUri = new Uri("Tobi.ico", UriKind.RelativeOrAbsolute);
                //Uri iconUri = new Uri("pack://application:,,,/Tobi;component/Tobi.ico", UriKind.Absolute);

                string appFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string iconPath  = Path.Combine(appFolder, "Shortcut.ico");
                var    iconUri   = new Uri("file://" + iconPath, UriKind.Absolute);

                Icon = BitmapFrame.Create(iconUri);
            }
            finally
            {
                //ignore
            }

            OnPropertyChangedButtonsSet();

            Button buttonToFocus = ButtonOK;
            switch (DefaultDialogButton)
            {
            case DialogButton.Yes:
            {
                buttonToFocus = ButtonYes;
                break;
            }

            case DialogButton.Ok:
            {
                buttonToFocus = ButtonOK;
                break;
            }

            case DialogButton.No:
            {
                buttonToFocus = ButtonNo;
                break;
            }

            case DialogButton.Close:
            {
                buttonToFocus = ButtonClose;
                break;
            }

            case DialogButton.Cancel:
            {
                buttonToFocus = ButtonCancel;
                break;
            }

            case DialogButton.Apply:
            {
                buttonToFocus = ButtonApply;
                break;
            }
            }

            FocusHelper.Focus(buttonToFocus);
        }