1
我想要什么
我想在WP7.5中显示一个自定义活动切片,一个文本块和一个带有4个字符串作为其listitem的列表框。因此,我创建了一个包含所有内容的图像并将其显示为活动图块的背景。为什么我看不到PNG文件中的列表框?
我的代码
//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();
结局是什么
我可以看到文本块,但我看不到列表框中。我试图直接分配下面
for (int i=0, i<TaskList.Length, i++)
{
Listbox1.Items.Add(TaskList[i]);
}
使用的代码的字符串数组(任务列表[])到列表框的项,但结果是我不能看到这一点。
我该如何解决这个问题?为什么我看不到图片中的列表框?
但似乎他们都在一个单一的行......所有的内容都乱了,我试图设置textblock的每个边距,但它不工作。为什么? –
所有在堆叠面板或网格的一行?如果网格,然后添加两行,如果stackpanel,那么你让我难倒 –