private static void buildAttachmentsPanel(StackPanel attachmentsStackPanel, MultipleAttachmentsInfo attachments) { if (attachments != null && attachments.LinkUrls != null && attachments.DisplayTextValues != null) { int count = Math.Max(attachments.LinkUrls.Count(), attachments.DisplayTextValues.Count()); for (int i = 0; i < count; i++) { string linkUrl = attachments.LinkUrls.ElementAtOrDefault(i); string link = attachments.DisplayTextValues.ElementAtOrDefault(i); attachmentsStackPanel.Children.Add(createHyperlinkButton(linkUrl, link)); } } }
private static void setupAttachments(AttachmentsPanel panel, AttachmentFieldValue attachmentFieldValue) { if (attachmentFieldValue != null && attachmentFieldValue.AttachmentsProvider != null) { if (attachmentFieldValue.AttachmentsProvider.HasAlreadyRetrievedAttachments()) { MultipleAttachmentsInfo attachments = attachmentFieldValue.AttachmentsProvider.GetAttachments(); panel.setAttachments(attachments); } else { attachmentFieldValue.AttachmentsProvider.LoadAttachments(attachmentFieldValue.LinkUrl, (o, args) => { panel.Dispatcher.BeginInvoke((Action) delegate { if (args == null) { return; } AttachmentsPanel pnl = args.UserState as AttachmentsPanel; pnl.setAttachments(args.AttachmentInfo); }); }, (o, args) => { panel.Dispatcher.BeginInvoke((Action) delegate { if (args == null || args.Exception == null) { return; } AttachmentsPanel pnl = args.UserState as AttachmentsPanel; pnl.Error = args.Exception.Message; pnl.ErrorVisibility = Visibility.Visible; }); }, panel); } } }
void setAttachments(MultipleAttachmentsInfo attachments) { if (attachments != null && attachments.LinkUrls != null && attachments.DisplayTextValues != null) { int count = Math.Max(attachments.LinkUrls.Count(), attachments.DisplayTextValues.Count()); if (Attachments == null) { Attachments = new ObservableCollection <AttachmentInfo>(); } else { Attachments.Clear(); } for (int i = 0; i < count; i++) { string url = attachments.LinkUrls.ElementAtOrDefault(i); string name = attachments.DisplayTextValues.ElementAtOrDefault(i); Attachments.Add(new AttachmentInfo() { Name = name, Url = url }); } } }