Exemplo n.º 1
0
        /// <summary>
        /// Update ellipse with the most recent contact data. If an ellipse has not
        /// been created yet, create one.
        /// </summary>
        /// <param name="contact">the contact to diagram</param>
        private void UpdateEllipse(Contact contact)
        {
            UIElement relativeTo = this;

            // Create an ellipse if one does not exist already.
            if (twoToneEllipse == null)
            {
                // Request an ellipse with the proper dimensions and RenderTransform.
                twoToneEllipse = contact.GetEllipse(relativeTo);

                // Give the ellipse a two color fill.
                LinearGradientBrush twoToneBrush = new LinearGradientBrush();
                twoToneBrush.StartPoint = new Point(1.0, 0.5);
                twoToneBrush.EndPoint = new Point(0.0, 0.5);
                GradientStopCollection gradientStops = new GradientStopCollection();
                gradientStops.Add(new GradientStop(Colors.Green, 0.49));
                gradientStops.Add(new GradientStop(Colors.LimeGreen, 0.51));
                twoToneBrush.GradientStops = gradientStops;
                twoToneEllipse.Fill = twoToneBrush;

                // Add the ellipse to the MainCanvas.
                MainCanvas.Children.Add(twoToneEllipse);

                // Give the Ellipse a lower ZIndex than the ConnectingLine and Description
                // so it is not drawn on top of them.
                Canvas.SetZIndex(twoToneEllipse, -1);
            }
            else
            {
                // This diagram already has an ellipse. Update the existing ellipse
                // dimensions and RenderTransform so the shape will match the contact.
                contact.UpdateEllipse(twoToneEllipse, relativeTo);
            }
        }