我正在Windows Phone 8上的后台代理中制作自定义图像,以显示在我的实时图块背面。我遇到了一个小问题,我无法让我的文字包装工作。
我首先创建一个画布,然后保存文本块。我试过把一个堆叠板放在两者之间,但没有运气。我将TextWrapping设置为Wrap,设置(max)height&所有元素的(最大)宽度,但没有运气。我也尝试过将修剪设置为无。
以下是代码:
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();
}
我也有一个小问题,有时图像没有按时完成渲染/保存,而且图块显示旧版本,但我仍然在看着它。
谢谢!
约恩