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


C# DrawingContext.DrawCenterText方法代码示例

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


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

示例1: RowRender

        protected override void RowRender(int index, double top, DrawingContext dc)
        {
            foreach (var item in Element.GetItems(index, GetViewRange()))
            {
                var block = item as ITerm;

                if (block == null)
                    continue;

                if (OutOfVisualRange(block))
                    continue;

                var rect = block.Start.Date.ToRect(Element.AxisXConverter, top, Element.BlockConverter.GetHeight(block));

                if (Element.BlockConverter.IsDirty(block))
                    dc.DrawRectangle(Background, null, rect.SetMargin(new Thickness(0, 0, 0, 1)));

                dc.DrawCenterText(Element.BlockConverter.GetContentText(block), rect, Element.BlockConverter.GetForeground(block));
            }

            //var itemsSource = Element.ItemsSource;
            //var axisXConverter = Element.AxisXConverter;
            //var blockConverter = Element.BlockConverter;
            //var screenStart = axisXConverter.ScreenToData(0);
            //var screenEnd = axisXConverter.ScreenToData(Element.RenderSize.Width);

            //var terms = itemsSource[index];
            //if (terms == null) return;

            //foreach (var item in terms)
            //{
            //    var block = item as ITerm;
            //    if (block == null)
            //        continue;
            //    var blockStart = block.Start;
            //    var blockEnd = block.End;

            //    if (blockStart > screenEnd || blockEnd < screenStart)
            //        continue;

            //    var blockLeft = axisXConverter.DataToScreen(blockStart);
            //    var blockRight = axisXConverter.DataToScreen(blockEnd);
            //    var blockHeight = Element.Interval;
            //    var blockTop = 0;

            //    //new Pen(Brushes.Black,1)
            //    var rect = new Rect(blockLeft, blockTop, blockRight - blockLeft, blockHeight);
            //    context.DrawRectangle(blockConverter.GetBackground(block), null, rect);
            //    //班名
            //    var text = blockConverter.GetContentText(block);
            //DrawCenterText(text, "/", blockConverter.FontSize, rect, Brushes.Black, context);
            //}
        }
开发者ID:Mrding,项目名称:Ribbon,代码行数:53,代码来源:TextGridDraw.cs

示例2: RowRender

        protected override void RowRender(int index, double top, DrawingContext dc)
        {
            var viewRange = GetViewRange();
            var height = Element.Interval;

            Element.GetItems(index, viewRange).SaftyInvoke<IDateIndexer<ITerm>>(o =>
            {
                var day = viewRange.Start.Date;
                var end = viewRange.End.Date;
                while (day < end)
                {
                    var block = o[day];
                    if (block != null)
                    {
                        var foreground = Element.BlockConverter.GetForeground(block);

                        var rect = day.ToRect(Element.AxisXConverter, top, height);

                        var dateTerm = Element.ItemsSource[index].SaftyGetProperty<DateTerm, IDateIndexer<DateTerm>>(t => t[day]);
                        

                        if (dateTerm != null && Background != Brushes.Transparent && Background != null)
                        {
                            // dc.DrawGuidelineRect(null, _pen, rect.SetMargin(new Thickness(0, -1, 0, 1)));

                            dc.DrawRectangle( Element.BlockConverter.GetBackground(block) ?? Background, null, rect.SetMargin(new Thickness(1, 0, 0, 0.5))); //like dirty cell
                        }

                        if (dateTerm != null && !string.IsNullOrEmpty(dateTerm.Text))
                        {
                            dc.DrawCenterText(dateTerm.Text, rect, foreground);
                        }
                        else
                        {
                            var text = Element.BlockConverter.GetContentText(block);
                            if (!string.IsNullOrEmpty(text))
                            {
                                FormattedText formattedText;

                                if (!_formatedTextCaches.ContainsKey(text))
                                {
                                    formattedText = text.ToFormattedText(foreground);
                                    var charWidth = formattedText.Width / text.Length;
                                    if (formattedText.Width > rect.Width)
                                    {
                                        var maxChar = (int)(rect.Width / charWidth);
                                        formattedText = text.Substring(0, maxChar).ToFormattedText(foreground);
                                    }
                                    _formatedTextCaches[text] = new Tuple<FormattedText, double>(formattedText, ((rect.Height - formattedText.Baseline) / 2));
                                }
                                else
                                    formattedText = _formatedTextCaches[text].Item1;

                                var horizontailMargin = (rect.Width - formattedText.Width) / 2; //margin left & right

                                //Item1 = formatedText , Item2 = top margin
                                if(dateTerm==null)
                                    Element.BlockConverter.GetBackground(block).SaftyInvoke(
                                        b => dc.DrawRectangle(b, null, rect.SetMargin(new Thickness(1, 0, 0, 0.5))));

                                dc.DrawText(formattedText, new Point(rect.Left + horizontailMargin, rect.Top + _formatedTextCaches[text].Item2));
                                
                            }
                        }
                    }
                    day = day.AddDays(1);
                }
            });

            //Element.ItemsSource[index].SaftyInvoke<IDateIndexer<DateTerm>>(o =>
            //{
            //    var viewRange = GetViewRange();
            //    var day = viewRange.Start.Date;
            //    var end = viewRange.End.Date.AddDays(1);
            //    while (day < end)
            //    {
            //        var dateTerm = o[day];
            //        if (dateTerm != null)
            //        {
            //            var rect = dateTerm.Date.ToRect(Element.AxisXConverter, 0, Element.Interval);
            //            dc.DrawRectangle(Background, null, rect.SetMargin(new Thickness(0, 0, 0, 1)));
            //            dc.DrawCenterText(dateTerm.Text, rect, Brushes.White);
            //        }

            //        day = day.AddDays(1);
            //    }
            //});

            //Element.ItemsSource[index].SaftyInvoke<IDateIndexer<DateTerm>>(o =>
            //{
            //    var viewRange = GetViewRange();
            //    var day = viewRange.Start.Date;
            //    var end = viewRange.End.Date.AddDays(1);
            //    while (day < end)
            //    {
            //        var dateTerm = o[day];
            //        if (dateTerm != null)
            //        {
            //            var rect = dateTerm.Date.ToRect(Element.AxisXConverter, 0, Element.Interval);
            //            dc.DrawRectangle(Background, null, rect.SetMargin(new Thickness(0, 0, 0, 1)));
//.........这里部分代码省略.........
开发者ID:Mrding,项目名称:Ribbon,代码行数:101,代码来源:CellBlockGridDraw.cs


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