2

liveTileでカスタムフォントリソースを使用してカスタムテキストブロックをレンダリングする際に問題が発生しましたか?

私のプロジェクトは、バックグラウンドでライブタイルを更新します。しかし、それはパーソナライズする必要があります。

このコードを使用しています。しかし、それはうまくいきません。埋め込みフォントを使おうとすると、テキストは空白で表示されます。ビットマップの背景は問題なく機能します。しかし、フォントは機能しません。

「フォアグラウンドエージェント」でこれと同じコードを使用すると、フォントが完全に表示されます。

Grid grid = new Grid();

// load your image 
StreamResourceInfo info = Application.GetResourceStream(new Uri("tile.jpg", UriKind.Relative));

// create source bitmap for Image control (image is assumed to be alread 173x173)
WriteableBitmap wbmp2 = new WriteableBitmap(1, 1);
wbmp2.SetSource(info.Stream);
Image img = new Image();
img.Source = wbmp2;

// add Image to Grid
grid.Children.Add(img);

TextBlock text = new TextBlock() 
{
    FontFamily = new FontFamily("/MyTaskAgent;component/Fonts/Fonts.zip#Buxton Sketch"),
    Foreground = new SolidColorBrush(Colors.Black) ,
    TextWrapping = TextWrapping.Wrap,
};

text.Text = "Test";

// this is our final image containing custom text and image
WriteableBitmap wbmp = new WriteableBitmap(173, 173);

// now render everything - this image can be used as background for tile
wbmp.Render(grid, null);
wbmp.Invalidate();
4

2 に答える 2

2

私も同様の問題を抱えていて、解決策を見つけました。こちらまたはこちらをご覧ください

要約すると、1。変換を行う前にフォントを使用する非表示のテキストブロックを作成するか、2。FontSourceを作成します。

今のところ簡単だったので、最初のものを使用しました。

テキストブロックは非表示になっていますが、埋め込みフォントが確実に読み込まれます。

私のコントロールの中に、私は以下を追加しました:

void Grid_Loaded(object sender, RoutedEventArgs e) {
#if SILVERLIGHT
    Grid Grid = (Grid)sender;
    AddFontLoaderTextBox(Grid, "Signs Road Features");
    AddFontLoaderTextBox(Grid, "Signs G Old");
    AddFontLoaderTextBox(Grid, "Signs G");
    AddFontLoaderTextBox(Grid, "Signs G1");
    AddFontLoaderTextBox(Grid, "Signs G2");
    AddFontLoaderTextBox(Grid, "Signs G3");
    AddFontLoaderTextBox(Grid, "Signs Info");
    AddFontLoaderTextBox(Grid, "Signs Regulatory");
    AddFontLoaderTextBox(Grid, "Signs Regulatory1");
    AddFontLoaderTextBox(Grid, "Road Manager");
    AddFontLoaderTextBox(Grid, "Signs Temporary");
    AddFontLoaderTextBox(Grid, "Road Manager");
    AddFontLoaderTextBox(Grid, "Signs Warning");
    AddFontLoaderTextBox(Grid, "Signs Warning1");
#endif
}

#if SILVERLIGHT
void AddFontLoaderTextBox(Grid Grid, string fontName) {

    TextBlock TextBlock = new TextBlock();
    TextBlock.FontFamily = new FontFamily(string.Format(
        "pack://application:,,,/ITIS.Controls.LinearViewer.Silverlight;component/Fonts/{0}.ttf#{0}", fontName));
    TextBlock.Opacity = 0; /* hide the text block, we only load it for the font to be cached */
    Grid.SetRowSpan(TextBlock, 3); /* just to ensure the text block doesn't affect the size of the first row */
    Grid.Children.Insert(0, TextBlock); /* keep underneath other children */
}
#endif
于 2012-09-06T10:57:25.647 に答える
1

問題が投稿されたコードに関連しているとは思えません。カスタムフォントの読み込みにはかなりの時間がかかる可能性があります。そのため、フォントが読み込まれる前にバックグラウンドエージェントが終了し、何もレンダリングされません。

電話をかける前に、レンダリングが完了したことを確認しますNotifyComplete()か?

于 2012-01-02T08:22:29.907 に答える