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); } } }
static void OnValueChange(DependencyObject obj, DependencyPropertyChangedEventArgs a) { AttachmentsPanel panel = obj as AttachmentsPanel; if (panel.FieldValue is AttachmentFieldValue) { setupAttachments(panel, panel.FieldValue as AttachmentFieldValue); } }
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); } } }