0

我正在 Windows Phone 8 的后台代理中制作自定义图像,以显示在动态磁贴的背面。我遇到了一个小问题,我无法让我的文本换行工作。

我首先创建一个画布,然后保存文本块。我尝试在两者之间放置一个堆栈面板,但没有运气。我将 TextWrapping 设置为 Wrap,我在所有元素上设置了(最大)高度和(最大)宽度,但没有运气。我也尝试将修剪设置为无。

这是代码:

        private void UpdateAppTile(string message, int stuntCount)
    {
        System.Threading.ManualResetEvent mre = new System.Threading.ManualResetEvent(false);

        Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                var can = new Canvas();
                can.Background = new SolidColorBrush(Color.FromArgb(255, 255, 204, 0));
                can.Width = 336;
                can.Height = 336;
                can.MaxHeight = 336;
                can.MaxWidth = 336;
                TextBlock textBlock = new TextBlock();
                textBlock.FontSize = 26;
                textBlock.Foreground = new SolidColorBrush(Color.FromArgb(255, 51, 102, 153));
                textBlock.TextWrapping = TextWrapping.Wrap;

                textBlock.Padding = new Thickness(10,10,10,10);
                textBlock.MaxHeight = 336;
                textBlock.MaxWidth = 336;
                textBlock.MaxHeight = 336;
                textBlock.MaxWidth = 336;
                textBlock.TextTrimming = TextTrimming.None;
                textBlock.Text = message;
                StackPanel stackPanel = new StackPanel();
                stackPanel.MaxHeight = 336;
                stackPanel.MaxWidth = 336;
                stackPanel.MaxHeight = 336;
                stackPanel.MaxWidth = 336;
                stackPanel.Children.Add(textBlock);
                can.Children.Add(stackPanel);

                const string liveTilePath = "/Shared/ShellContent/live_tile.jpg";

                var writeableBitmap = new WriteableBitmap(336, 336);
                writeableBitmap.Render(can, null);
                writeableBitmap.Invalidate();

                using (
                    var isoFileStream = new IsolatedStorageFileStream(liveTilePath, FileMode.OpenOrCreate,
                                                                      IsolatedStorageFile.GetUserStoreForApplication
                                                                          ()))
                {
                    writeableBitmap.SaveJpeg(isoFileStream, 336, 336, 0, 100);
                }

                ShellTile appTile = ShellTile.ActiveTiles.First();
                if (appTile != null)
                {
                    FlipTileData tileData = new FlipTileData
                        {
                            BackBackgroundImage = new Uri("isostore:" + liveTilePath, UriKind.Absolute),
                            BackContent = "",
                            Title = "Set at " + DateTime.Now.ToShortTimeString()
                        };
                    tileData.Count = stuntCount;
                    appTile.Update(tileData);

                }
            });

        mre.WaitOne();
        NotifyComplete();
    }

我也有一个小问题,有时图像没有按时完成渲染/保存,并且磁贴显示旧版本,但我仍在研究。

谢谢 !

乔恩

4

0 回答 0