我制作了这个 Windows Phone 用户控件:
XAML:
<Grid x:Name="LayoutRoot" Height="75" Width="353">
<Image Height="50" HorizontalAlignment="Left" Margin="12,12,0,0" Name="img" Stretch="Fill" VerticalAlignment="Top" Width="50" />
<TextBlock Height="50" HorizontalAlignment="Left" Margin="77,12,0,0" Name="txt" Text="TextBlock" VerticalAlignment="Top" Width="215" FontSize="32" />
<CheckBox Content="CheckBox" Height="68" HorizontalAlignment="Right" Margin="0,3,10,0" Name="cb" VerticalAlignment="Top" Width="50" />
</Grid>
我在我的一个页面中这样称呼它
XAML.CS:
myListBox mls = new myListBox();
String[,] ls = { { "Text1", "/image/image1.png" }, { "Tex2", "/image/image2.png" } };
for (int i = 0; i < 2; i++)
{
mls.txt.Text = ls[i, 0];
mls.img.Source = url(ls[i, 1]);
}
public ImageSource url (string path)
{
Uri uri = new Uri(path, UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
return imgSource;
}
我的问题是:
1)如果我像这样运行它需要下面的代码但是如果我将for循环更改为i<1
它工作正常(但不完全是我期望的问题2)
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
2)使用此代码,我设置了文本和图像,但它没有放置图像,只有文本。