コード例 #1
0
ファイル: GeoMap.cs プロジェクト: Uwy/Live-Charts
        private void Draw()
        {
            IsDrawn = true;

            Map.Children.Clear();

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                Map.Children.Add(new TextBlock
                {
                    Text       = "Designer preview is not currently available",
                    Foreground = new SolidColorBrush(Colors.White),
                    FontWeight = FontWeights.Bold,
                    FontSize   = 12,
                    //Effect = new DropShadowEffect
                    //{
                    //    ShadowDepth = 2,
                    //    RenderingBias = RenderingBias.Performance
                    //}
                });
                return;
            }

            var map = MapResolver.Get(Source);

            if (map == null)
            {
                return;
            }

            var desiredSize = new Size(map.DesiredWidth, map.DesiredHeight);
            var r           = desiredSize.Width / desiredSize.Height;

            var    wr = ActualWidth / desiredSize.Width;
            var    hr = ActualHeight / desiredSize.Height;
            double s;

            if (wr < hr)
            {
                IsWidthDominant = true;
                Map.Width       = ActualWidth;
                Map.Height      = Map.Width / r;
                s = wr;
                OriginalPosition = new Point(0, (ActualHeight - Map.Height) * .5);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }
            else
            {
                IsWidthDominant = false;
                Map.Height      = ActualHeight;
                Map.Width       = r * ActualHeight;
                s = hr;
                OriginalPosition = new Point((ActualWidth - Map.Width) * .5, 0d);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }

            var t = new ScaleTransform()
            {
                ScaleX = s, ScaleY = s
            };

            foreach (var land in map.Data)
            {
                var p = new Path
                {
                    Data            = GeometryHelper.Parse(land.Data),
                    RenderTransform = t
                };

                land.Shape     = p;
                Lands[land.Id] = land;
                Map.Children.Add(p);

                //p.MouseEnter += POnMouseEnter;
                //p.MouseLeave += POnMouseLeave;
                //p.MouseMove += POnMouseMove;
                //p.MouseDown += POnMouseDown;

                p.SetBinding(Shape.StrokeProperty,
                             new Binding {
                    Path = new PropertyPath("LandStroke"), Source = this
                });
                var behavior = new MultiBindingBehavior()
                {
                    Converter    = new ScaleStrokeConverter(),
                    PropertyName = "StrokeThickness"
                };
                behavior.Items.Add(new MultiBindingItem()
                {
                    Parent = behavior.Items, Value = new Binding()
                    {
                        Path = new PropertyPath("LandStrokeThickness"), Source = this
                    }
                });
                behavior.Items.Add(new MultiBindingItem()
                {
                    Parent = behavior.Items, Value = new Binding()
                    {
                        Path = new PropertyPath("ScaleX"), Source = t
                    }
                });
                Interaction.SetBehaviors(p, new BehaviorCollection()
                {
                    behavior
                });
            }

            ShowMeSomeHeat();
        }
コード例 #2
0
ファイル: GeoMap.cs プロジェクト: beto-rodriguez/Live-Charts
        private void Draw()
        {
            IsDrawn = true;

            Map.Children.Clear();

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                Map.Children.Add(new TextBlock
                {
                    Text = "Designer preview is not currently available",
                    Foreground = new SolidColorBrush(Colors.White),
                    FontWeight = FontWeights.Bold,
                    FontSize = 12,
                    //Effect = new DropShadowEffect
                    //{
                    //    ShadowDepth = 2,
                    //    RenderingBias = RenderingBias.Performance
                    //}
                });
                return;
            }

            var map = MapResolver.Get(Source);
            if (map == null) return;

            var desiredSize = new Size(map.DesiredWidth, map.DesiredHeight);
            var r = desiredSize.Width/desiredSize.Height;

            var wr = ActualWidth/desiredSize.Width;
            var hr = ActualHeight/desiredSize.Height;
            double s;

            if (wr < hr)
            {
                IsWidthDominant = true;
                Map.Width = ActualWidth;
                Map.Height = Map.Width/r;
                s = wr;
                OriginalPosition = new Point(0, (ActualHeight - Map.Height)*.5);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }
            else
            {
                IsWidthDominant = false;
                Map.Height = ActualHeight;
                Map.Width = r*ActualHeight;
                s = hr;
                OriginalPosition = new Point((ActualWidth - Map.Width)*.5, 0d);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }

            var t = new ScaleTransform() {ScaleX = s, ScaleY = s};

            foreach (var land in map.Data)
            {
                var p = new Path
                {
                    Data = GeometryHelper.Parse(land.Data),
                    RenderTransform = t
                };

                land.Shape = p;
                Lands[land.Id] = land;
                Map.Children.Add(p);

                //p.MouseEnter += POnMouseEnter;
                //p.MouseLeave += POnMouseLeave;
                //p.MouseMove += POnMouseMove;
                //p.MouseDown += POnMouseDown;

                p.SetBinding(Shape.StrokeProperty,
                    new Binding { Path = new PropertyPath("LandStroke"), Source = this });
                var behavior = new MultiBindingBehavior()
                {
                    Converter = new ScaleStrokeConverter(),
                    PropertyName = "StrokeThickness"
                };
                behavior.Items.Add(new MultiBindingItem() {Parent = behavior.Items, Value = new Binding() { Path = new PropertyPath("LandStrokeThickness"), Source = this } });
                behavior.Items.Add(new MultiBindingItem() {Parent = behavior.Items, Value = new Binding() { Path = new PropertyPath("ScaleX"), Source = t } });
                Interaction.SetBehaviors(p, new BehaviorCollection() {behavior});
            }

            ShowMeSomeHeat();
        }