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()); }
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); } }