【发布时间】:2020-06-25 19:07:08
【问题描述】:
我已经成功地在 XAML 中创建了一个图像,在一个网格中,在 AbsoulteLayout 中
<Image HeightRequest="15" WidthRequest="15"
Source="{local:ImageResource ScKWander.Images.UI.arrow_pointer_R.png}"
TranslationY="330" TranslationX="15"
/>
我正在尝试在后面的代码中创建图像,以便更改代码中的位置。虽然我尝试了几种可能的替代方案,但没有任何效果。下面的代码编译并运行没有错误。 Catch 永远不会被击中,屏幕上唯一的东西是在 XAML 中创建的一个图像。我只打算将网格用作容器,但如果需要,我可以使用网格行/列。在 UWP 中,我使用的是画布。
我尝试了几种不同的源代码编码方法,但都失败了。除了那个,我把所有的都拿出来了。
我应该补充一下,我现在遇到了几个 Xamarin 错误。我认为它是新的建筑。我不认为这些影响了这一点。我构建、运行并看到一个由 XAML 定义的箭头。
private void FillGrid()
{
int iYoffset = 15;
int iXoffset = 15;
int iYGridsize = 25;
int iXGridsize = 25;
try
{
for (int iCount0 = 0; iCount0 < 5; iCount0++)
{
for (int iCount1 = 0; iCount1 < 5; iCount1++)
{
var thisImage = new Image { Source = ImageSource.FromResource
("local:ImageResource ScKWander.Images.UI.arrow_pointer_R.png") };
//thisImage.TranslationY = iYoffset + (iCount0 * iYGridsize);
//thisImage.TranslationX = iXoffset + (iCount1 * iXGridsize);
thisImage.HeightRequest = 25;
thisImage.WidthRequest = 25;
gridBoard.Children.Add(thisImage, iCount0 * iYGridsize, iCount1 * iXGridsize);
}
}
}
catch (Exception e)
{
string ex = e.Message;
}
}
【问题讨论】: