WP7.5 でカスタム ライブ タイル、テキストブロック、およびリスト項目として 4 つの文字列を含むリスト ボックスを表示したいと考えています。そのため、すべてのものを含む画像を作成し、ライブ タイルの背景として表示します。
私がコードするもの
//prepare the background
WriteableBitmap bmp = new WriteableBitmap(173, 173);
BitmapImage logo = new BitmapImage(new Uri("/images/tile/SecondaryTile.png", UriKind.Relative));
Image img = new Image { Source = logo };
// Force the bitmapimage to load it's properties so the transform will work
logo.CreateOptions = BitmapCreateOptions.None;
//create a textblock
TextBlock taskNumberShow = new TextBlock();
taskNumberShow.Foreground = new SolidColorBrush(Colors.White);
taskNumberShow.FontSize = 35;
taskNumberShow.HorizontalAlignment = HorizontalAlignment.Center;
taskNumberShow.FontFamily = (FontFamily)Application.Current.Resources["PhoneFontFamilySemiBold"];
taskNumberShow.Text = "35";
//define the position
TranslateTransform tt1 = new TranslateTransform();
tt1.X = 45;
tt1.Y = 7;
bmp.Render(taskNumberShow, tt1);
//create a listbox
ListBox listBox1 = new ListBox();
listBox1.Height = 100;
listBox1.Width = 173;
listBox1.HorizontalAlignment = HorizontalAlignment.Center;
//listBox1.VerticalAlignment = VerticalAlignment.Bottom;
//listBox1.Margin = new Thickness(50, 150, 0, 0);
//put a string array in the listbox, the length of this array is 4
for (int i=0; i < TaskList.Length; i++)
{
//先生成一堆textBlock
TextBlock txtBlk = new TextBlock();
txtBlk.Name = "txtBlk" + i.ToString();
txtBlk.Text = TaskList[i];
txtBlk.FontSize = 17;
txtBlk.Width = 173;
txtBlk.TextWrapping = TextWrapping.NoWrap;
txtBlk.Foreground = new SolidColorBrush(Colors.White);
listBox1.Items.Add(txtBlk);
}
//define the position
tt1.X = 0;
tt1.Y = 40;
bmp.Render(listBox1, tt1);
//add the backgroundpic
tt1.X = 0;
tt1.Y = 0;
bmp.Render(img, tt1);
bmp.Invalidate();
ExtendedImage extendImage = bmp.ToImage();
テキストブロックは
見えますが、リストボックスが見えません。以下のコードを使用して、文字列配列(TaskList[])のアイテムをリストボックスに直接割り当てようとしました
for (int i=0, i<TaskList.Length, i++)
{
Listbox1.Items.Add(TaskList[i]);
}
しかし、結果は私もそれを見ることができません。
この問題を解決するにはどうすればよいですか? 写真にリストボックスが表示されないのはなぜですか?