当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.InvalidateVisual方法代码示例

本文整理汇总了C#中System.Windows.Controls.Canvas.InvalidateVisual方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.InvalidateVisual方法的具体用法?C# Canvas.InvalidateVisual怎么用?C# Canvas.InvalidateVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Canvas的用法示例。


在下文中一共展示了Canvas.InvalidateVisual方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderPage

        /// <summary>
        /// Renders the contents of the target canvas
        /// </summary>
        /// <param name="Canvas">target canvas</param>
        private void RenderPage(Canvas Canvas)
        {
            try
            {
                Canvas.Children.RemoveRange(0, Canvas.Children.Count);
                foreach (PageElement PE in this.CurrentBook.Pages[viewIndex].Children)
                {
                    ContentControl cc = FormContentControl(PE);

                    cc.Height = PE.Height;
                    cc.Width = PE.Width;
                    if (PE.ControlType == "System.Windows.Controls.RichTextBox")
                    {
                        GenerateTextBox(PE, cc);
                    }
                    else if (PE.ControlType == "System.Windows.Controls.Image")
                    {
                        GenerateImage(PE, cc);
                    }
                    else if (PE.ControlType == "System.Windows.Shapes.Ellipse")
                    {
                        Ellipse e = new Ellipse();
                        e.Fill = new BrushConverter().ConvertFromString(PE.Child.Brush) as SolidColorBrush;
                        cc.Content = e;
                    }
                    else if (PE.ControlType == "System.Windows.Shapes.Rectangle")
                    {
                        Rectangle r = new Rectangle();
                        r.Fill = new BrushConverter().ConvertFromString(PE.Child.Brush) as SolidColorBrush;
                        cc.Content = r;
                    }

                    if (!string.IsNullOrWhiteSpace(PE.ControlType))
                    {
                        Canvas.Children.Add(cc);
                    }

                }
                //re-renders the page
                Canvas.InvalidateVisual();
            }
            catch (Exception ex)
            {
                if (ex is ArgumentOutOfRangeException)
                {
                    host.statuspanel.Background = Brushes.LightCoral;
                    host.lbxstatus.Content = "Error: Page Doesnt Exist";
                }
            }
        }
开发者ID:rakuza,项目名称:YBM2012,代码行数:54,代码来源:BookViewer.cs

示例2: _CreateRouteCanvas

        /// <summary>
        /// Creates canvas with invalidated route and its stops.
        /// </summary>
        /// <param name="route">Route to draw.</param>
        /// <param name="sortedRouteStops">Sorted stops from route.</param>
        /// <param name="mapImage">Map image.</param>
        /// <returns>Canvas with invalidated route and its stops.</returns>
        private SysControls.Canvas _CreateRouteCanvas(Route route, IList<Stop> sortedRouteStops, MapImage mapImage)
        {
            Debug.Assert(null != route);
            Debug.Assert(null != mapImage);
            Debug.Assert(null != sortedRouteStops);

            // create canvas
            var canvas = new SysControls.Canvas();
            canvas.InvalidateVisual();
            canvas.Height = mapImage.ImageHeight;
            canvas.Width = mapImage.ImageWidth;

            // init route brush from route color
            System.Drawing.Color color = route.Color;
            var mediaColor =
                SysWindows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
            var fillingBrush = new SolidColorBrush(mediaColor);

            // create and init route image
            SymbolControl routeBox = new SymbolControl(_routeSymbolTemplate);
            routeBox.Geometry = _CreatePath(route,
                                            sortedRouteStops,
                                            mapImage.Extent,
                                            mapImage.ImageWidth,
                                            mapImage.ImageHeight);
            routeBox.Fill = (SolidColorBrush)fillingBrush.GetCurrentValueAsFrozen();
            routeBox.HorizontalAlignment = HorizontalAlignment.Stretch;
            routeBox.VerticalAlignment = VerticalAlignment.Stretch;
            // draw route
            canvas.Children.Add(routeBox);

            // draw stops - from last to first (visual elements)
            int stopLastIndex = sortedRouteStops.Count - 1;
            for (int index = stopLastIndex; index >= 0; --index)
            {
                Stop stop = sortedRouteStops[index];
                if (!stop.MapLocation.HasValue)
                    continue; // skip empty

                bool isVisible = true;
                if (stop.AssociatedObject is Location)
                {
                    if (index == 0)
                    {
                        isVisible = _showLeadingStemTime;
                    }
                    else if (index == stopLastIndex)
                    {
                        isVisible = _showTrailingStemTime;
                    }
                    // else do nothing
                }

                if (isVisible)
                {
                    UIElement element = _CreateStopUIElement(stop, mapImage, fillingBrush);
                    if (element != null)
                        canvas.Children.Add(element);
                }
            }

            return canvas;
        }
开发者ID:erindm,项目名称:route-planner-csharp,代码行数:70,代码来源:MapImageExporter.cs


注:本文中的System.Windows.Controls.Canvas.InvalidateVisual方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。