【发布时间】:2019-05-14 15:15:02
【问题描述】:
在这里,我正在创建一个动态网格视图。
private void PopulateImages()
{
ObservableCollection<Attachment> Images = new ObservableCollection<Attachment>();
Images.Add(new Attachment { Name = "Image 1", Index = 0 });
Images.Add(new Attachment { Name = "Image 2", Index = 1 });
Images.Add(new Attachment { Name = "Image 3", Index = 2 });
Images.Add(new Attachment { Name = "Image 4", Index = 3 });
Images.Add(new Attachment { Name = "Image 5", Index = 4 });
Images.Add(new Attachment { Name = "Image 6", Index = 5 });
gridLayout.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
gridLayout.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
gridLayout.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(33, GridUnitType.Star) });
gridLayout.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(33, GridUnitType.Star) });
gridLayout.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(33, GridUnitType.Star) });
gridLayout.ColumnSpacing = 8;
gridLayout.RowSpacing = 8;
var productIndex = 0;
for (int rowIndex = 0; rowIndex < 2; rowIndex++)
{
for (int columnIndex = 0; columnIndex < 3; columnIndex++)
{
if (productIndex >= Images.Count)
{
break;
}
var product = Images[productIndex];
productIndex += 1;
var frame = new Frame
{
HeightRequest = 95,
WidthRequest = 70,
CornerRadius = 10,
HasShadow = false,
BorderColor = Color.FromHex("#CCCCCC")
};
var image = new Image
{
Source = "addImage.png",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
HeightRequest = 35,
WidthRequest = 35
};
frame.Content = image;
TapGestureRecognizer tapped = new TapGestureRecognizer();
tapped.Tapped += (s, e) =>
{
TakePhoto();
};
frame.GestureRecognizers.Add(tapped);
gridLayout.Children.Add(frame, columnIndex, rowIndex);
}
}
}
当用户点击任何帧时,它会打开相机,捕捉后,图像将被设置为选定的帧。
那么如何获取这个网格的选中帧索引呢? 另外如何从这个图像视图中找到图像源?
是否有任何插件可用于使用此类功能以 xamarin 形式上传多张图片?
【问题讨论】:
标签: xamarin xamarin.forms