0

我有在 Application_Deacitvated/Closing() 中执行的方法。

public bool createBackTile()
    {
        if(AlarmClock.IsExists())
        {

            ImageBrush background = new ImageBrush()
            {
                ImageSource = new BitmapImage(new Uri("/BackBackgroundTheme.png", UriKind.Relative)),
                AlignmentX = AlignmentX.Center,
                AlignmentY = AlignmentY.Center
            };

            // Preparing tile image.
            TextBox tileImageData = new TextBox()
            {
                Text = AlarmClock.Read().ToShortTimeString(),
                FontSize = 45,
                FontWeight = FontWeights.Bold,
                Foreground = new SolidColorBrush(Colors.White),
                //Background = background,
                Height = 173,
                Width = 173,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment = VerticalAlignment.Center,
                Padding = new Thickness(-12),
                Margin = new Thickness(0),
                Clip = new RectangleGeometry { Rect = new Rect(0, 0, 173, 173) }
            };

            Canvas canvas = new Canvas()
            {
                Width = 173,
                Height = 173,
                Background = background,
                Margin = new Thickness(0)
            };

            canvas.Children.Add(tileImageData);

            // Saving tile image.
            WriteableBitmap tileImage = new WriteableBitmap(173, 173);
            tileImage.Render(canvas, null);
            tileImage.Render(tileImageData, null);
            tileImage.Invalidate();
            using(var stream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile("/Shared/ShellContent/BackBackground.jpg"))
            {
                tileImage.SaveJpeg(stream, 173, 173, 0, 100);
            }

            // Sets data for tile.
            StandardTileData tileData = new StandardTileData()
            {
                BackgroundImage = new Uri("BackgroundAlarmSet.png", UriKind.Relative),
                BackBackgroundImage = new Uri(@"isostore:/Shared/ShellContent/BackBackground.jpg"),
                BackContent = "",
                BackTitle = "",
            };

            // Sets tile.
            ShellTile.ActiveTiles.FirstOrDefault().Update(tileData);

            return true;
        }

        return false;
    }

因此,如您所见,我想生成带有图像背景“BackgroundTheme.png”的文本在其中心的图块。我试图保存在IsolatedStorage 中的那个图块并将其分配给BackBackgroundImage。

但它不起作用。瓷砖正在翻转,但背景是完全黑色的。我已经加载了这个经过处理的背景,看起来这确实只是一个黑匣子。那么,如何让它工作呢?

4

3 回答 3

0

尝试:BackgroundImage = new Uri(@"isostore:/Shared/ShellContent/BackBackground.jpg", UriKind.Absolute)

于 2012-05-03T19:02:46.280 回答
0

我终于找到了问题所在。

看来,平铺图像的生成在 Application_Closing/Deactivating() 中没有正确完成。因此,我将图像生成移至其他地方,现在,当应用程序关闭/停用时,我只是将先前生成的图像设置为图块。

于 2012-05-04T11:07:39.627 回答
0

试试这个:

canvas.Children.Add(tileImageData);
canvas.UpdateLayout();
        // Saving tile image.
        WriteableBitmap tileImage = new WriteableBitmap(173, 173);
于 2013-09-04T10:33:17.760 回答