我想要什么我想
在 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();
什么是 END
我可以看到文本块,但我看不到列表框。我尝试使用下面的代码将字符串数组(TaskList[])的项目直接分配给列表框
for (int i=0, i<TaskList.Length, i++)
{
Listbox1.Items.Add(TaskList[i]);
}
但结果是我也看不到。
我该如何解决这个问题?为什么我看不到图片中的列表框?