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


C# TextBlock.ToString方法代码示例

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


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

示例1: UpdateTileAsync

        private async Task UpdateTileAsync()
        {
            // create UI
            var grid = new Grid
            {
                VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch,
                HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch,
                Background=new SolidColorBrush(Colors.Red),
            };
            var star = new FontIcon
            {
                Glyph = "",
                FontSize = 50
            };
            grid.Children.Add(star);
            var number = new TextBlock
            {
                Text = 12.ToString(),
                FontSize = 25,
                Foreground = new SolidColorBrush(Colors.White)
            };
            grid.Children.Add(number);

            // create bitmap
            var bitmap = new RenderTargetBitmap();
            await bitmap.RenderAsync(grid, 150, 150);

            // create destination file
            var folder = ApplicationData.Current.LocalFolder;
            var file = await folder.CreateFileAsync("tile.png", CreationCollisionOption.ReplaceExisting);

            // write bitmap to file
            using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                var pixels = await bitmap.GetPixelsAsync();
                // using System.Runtime.InteropServices.WindowsRuntime;
                var bytes = pixels.ToArray();
                var encoder = await BitmapEncoder
                    .CreateAsync(BitmapEncoder.PngEncoderId, stream);
                var format = BitmapPixelFormat.Bgra8;
                var alpha = BitmapAlphaMode.Ignore;
                var width = (uint)bitmap.PixelWidth;
                var height = (uint)bitmap.PixelHeight;
                var dpi = DisplayInformation.GetForCurrentView().LogicalDpi;
                encoder.SetPixelData(format, alpha, width, height, dpi, dpi, bytes);
                await encoder.FlushAsync();
                stream.Seek(0);
            }
            await FileIO.WriteBytesAsync(file, null);

            // replace existing tile
            var type = TileTemplateType.TileSquare150x150Image;
            var xml = TileUpdateManager.GetTemplateContent(type);

            // no text on tile
            var elements = xml.GetElementsByTagName("binding");
            (elements[0] as XmlElement).SetAttribute("branding", "none");

            // image on tile
            elements = xml.GetElementsByTagName("image");
            (elements[0] as XmlElement).SetAttribute("src", file.Path);

            // update tile
            var notification = new TileNotification(xml);
            var updater = TileUpdateManager.CreateTileUpdaterForApplication();
            updater.Clear();
            updater.Update(notification);

            // prepare notification toast
            var toastTemplate = ToastTemplateType.ToastText01;
            xml = ToastNotificationManager.GetTemplateContent(toastTemplate);
            var text = xml.CreateTextNode(string.Format("Tile image updated to {0}", number));
            elements = xml.GetElementsByTagName("text");
            elements[0].AppendChild(text);

            // send toast
            var toast = new ToastNotification(xml);
            var notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.Show(toast);

            Debug.WriteLine("Background task toast shown: " + number.ToString());
        }
开发者ID:nmetulev,项目名称:WinDevCamp,代码行数:82,代码来源:MyUpdateTileTask.cs

示例2: drawBox

        private void drawBox()
        {
            int lt = this.chartBoxLineThickness;
            Color color = this.chartboxLineColor;

            // top line of the box
            drawLine(new Point(x, y), new Point(x + this.width, y), lt, color);
            // and we folow the box drawing lines clockwise
            drawLine(new Point(x + this.width, y), new Point(x + this.width, y + this.height), lt, color);
            drawLine(new Point(x + this.width, y + this.height), new Point(x, y + this.height), lt, color);
            drawLine(new Point(x, y + this.height), new Point(x, y), lt, color);

            Point p = new Point();
            p.X = x - 30;
            p.Y = y + this.height;

            for (int i = 30; i < 100; i += 10)
            {
                //draw amplines
                double amplitude = -i;
                double lineY = y + this.height - ((amplitude + 100.0) / 80.0) * this.height;
                Point startPoint = new Point(x, lineY);
                Point endPoint = new Point(x + width, lineY);
                drawLine(startPoint,endPoint, 1, Colors.Gray);

                TextBlock textBlock = new TextBlock();
                textBlock.Text = amplitude.ToString();
                Canvas.SetLeft(textBlock, startPoint.X - 30);
                Canvas.SetTop(textBlock, startPoint.Y - 10);

                this.activeCanvas.Children.Add(textBlock);
            }

            //draw channel numbers
            for (int i = 1; i < 14; i++)
            {
                double channelWidth = this.width / channelSpaces;

                double offset = 1 * channelWidth;

                //drawing of channel number numberline number
                Point startPoint = new Point(x + offset + (channelWidth) * i, y + this.height);
                Point endPoint = new Point(startPoint.X, startPoint.Y + 10);
                drawLine(startPoint, endPoint, 1, this.chartboxLineColor);

                //drawing of channel number
                Point channelNumberPoint = new Point(x + offset + (channelWidth) * i, y + this.height + 20);

                TextBlock textBlock = new TextBlock();
                textBlock.Text = i.ToString();
                double guestimatedLabelWidth = 8 * i.ToString().Length;
                Canvas.SetLeft(textBlock, channelNumberPoint.X - guestimatedLabelWidth / 2);
                Canvas.SetTop(textBlock, channelNumberPoint.Y - 10);

                this.activeCanvas.Children.Add(textBlock);

                if (1 == i && true != hideLabels)
                {
                    TextBlock channeltb = new TextBlock();
                    channeltb.Text = "Channel";
                    double guestimatedChannelLabelWidth = 4 * channeltb.ToString().Length;
                    Canvas.SetLeft(channeltb, channelNumberPoint.X - guestimatedChannelLabelWidth / 2);
                    Canvas.SetTop(channeltb, channelNumberPoint.Y - 10);
                    this.activeCanvas.Children.Add(channeltb);
                }
            }

            if (true != hideLabels)
            {
                TextBlock tb = new TextBlock();
                tb.Text = "dBm";
                RotateTransform rt = new RotateTransform();
                rt.Angle = -90;
                tb.RenderTransform = rt;
                Canvas.SetLeft(tb, p.X);
                Canvas.SetTop(tb, p.Y);
                this.activeCanvas.Children.Add(tb);
            }
        }
开发者ID:m3talelite,项目名称:WiFiVision,代码行数:79,代码来源:chartPlotter.cs


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