diff --git a/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml b/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml
index a9177d725..c0352ef92 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml
+++ b/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml
@@ -18,10 +18,12 @@
GeoViewTapped="mapView_GeoViewTapped"/>
+ VerticalAlignment="Stretch"
+ PopupAttachmentClicked="popupViewer_PopupAttachmentClicked"
+ HyperlinkClicked="popupViewer_LinkClicked" />
diff --git a/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml.cs b/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml.cs
index 8aab2bfdf..58bfa3d0b 100644
--- a/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml.cs
+++ b/src/Samples/Toolkit.SampleApp.UWP/Samples/PopupViewer/PopupViewerSample.xaml.cs
@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Threading.Tasks;
using Windows.UI.Popups;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -20,14 +21,10 @@ public sealed partial class PopupViewerSample : Page
public PopupViewerSample()
{
this.InitializeComponent();
- Map.Loaded += (s, e) =>
- {
- Map.OperationalLayers.RemoveAt(0); // Remove secured layer
- };
}
// Webmap configured with Popup
- public Map Map { get; } = new Map(new Uri("https://www.arcgis.com/home/item.html?id=d4fe39d300c24672b1821fa8450b6ae2"));
+ public Map Map { get; } = new Map(new Uri("https://www.arcgis.com/home/item.html?id=9f3a674e998f461580006e626611f9ad"));
private async void mapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
{
@@ -43,11 +40,11 @@ private async void mapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
if (popup != null)
{
popupViewer.Visibility = Visibility.Visible;
- popupViewer.PopupManager = new PopupManager(popup);
+ popupViewer.Popup = popup;
}
else
{
- popupViewer.PopupManager = null;
+ popupViewer.Popup = null;
popupViewer.Visibility = Visibility.Collapsed;
}
}
@@ -116,5 +113,45 @@ private Mapping.Popups.Popup GetPopup(IEnumerable results)
return null;
}
+ private async void popupViewer_PopupAttachmentClicked(object sender, UI.Controls.PopupAttachmentClickedEventArgs e)
+ {
+ // Override the default attachment click behavior (which will download and save attachment)
+ if (!e.Attachment.IsLocal) // Attachment hasn't been downloaded
+ {
+ try
+ {
+ // Make first click just load the attachment (or cancel a loading operation). Otherwise fallback to default behavior
+ if (e.Attachment.LoadStatus == LoadStatus.NotLoaded)
+ {
+ e.Handled = true;
+ await e.Attachment.LoadAsync();
+ }
+ else if (e.Attachment.LoadStatus == LoadStatus.FailedToLoad)
+ {
+ e.Handled = true;
+ await e.Attachment.RetryLoadAsync();
+ }
+ else if (e.Attachment.LoadStatus == LoadStatus.Loading)
+ {
+ e.Handled = true;
+ e.Attachment.CancelLoad();
+ }
+ }
+ catch (OperationCanceledException) { }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine("Failed to download attachment", ex.Message);
+ }
+ }
+ }
+
+ private void popupViewer_LinkClicked(object sender, UI.Controls.HyperlinkClickedEventArgs e)
+ {
+ // Include below line if you want to prevent the default action
+ // e.Handled = true;
+
+ // Perform custom action when a link is clicked
+ System.Diagnostics.Debug.WriteLine(e.Uri);
+ }
}
}
\ No newline at end of file
diff --git a/src/Toolkit/Toolkit.WPF/UI/Controls/PopupViewer/PopupViewer.Theme.xaml b/src/Toolkit/Toolkit.WPF/UI/Controls/PopupViewer/PopupViewer.Theme.xaml
index 598ac999e..d8c0566cc 100644
--- a/src/Toolkit/Toolkit.WPF/UI/Controls/PopupViewer/PopupViewer.Theme.xaml
+++ b/src/Toolkit/Toolkit.WPF/UI/Controls/PopupViewer/PopupViewer.Theme.xaml
@@ -52,62 +52,81 @@
+
+
+
-
-
-
-
-
+
diff --git a/src/Toolkit/Toolkit.WinUI/Esri.ArcGISRuntime.Toolkit.WinUI.csproj b/src/Toolkit/Toolkit.WinUI/Esri.ArcGISRuntime.Toolkit.WinUI.csproj
index aed9ead7c..c53aac9cc 100644
--- a/src/Toolkit/Toolkit.WinUI/Esri.ArcGISRuntime.Toolkit.WinUI.csproj
+++ b/src/Toolkit/Toolkit.WinUI/Esri.ArcGISRuntime.Toolkit.WinUI.csproj
@@ -44,7 +44,7 @@
-
+
diff --git a/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.Theme.xaml b/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.Theme.xaml
index ff840978d..d8af5c136 100644
--- a/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.Theme.xaml
+++ b/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.Theme.xaml
@@ -1,69 +1,213 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.Windows.cs b/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.Windows.cs
deleted file mode 100644
index 7d6b15248..000000000
--- a/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.Windows.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-// /*******************************************************************************
-// * Copyright 2012-2018 Esri
-// *
-// * Licensed under the Apache License, Version 2.0 (the "License");
-// * you may not use this file except in compliance with the License.
-// * You may obtain a copy of the License at
-// *
-// * http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing, software
-// * distributed under the License is distributed on an "AS IS" BASIS,
-// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// * See the License for the specific language governing permissions and
-// * limitations under the License.
-// ******************************************************************************/
-
-#if WINDOWS_XAML
-using Esri.ArcGISRuntime.Mapping.Popups;
-
-namespace Esri.ArcGISRuntime.Toolkit.UI.Controls
-{
- public partial class PopupViewer
- {
- private void Initialize() => DefaultStyleKey = GetType();
-
- ///
-#if WINDOWS_XAML
- protected override void OnApplyTemplate()
-#else
- public override void OnApplyTemplate()
-#endif
- {
- base.OnApplyTemplate();
- Refresh();
- }
-
- private void Refresh()
- {
- }
-
- ///
- /// Gets or sets the associated PopupManager which contains popup and sketch editor.
- ///
- private PopupManager? PopupManagerImpl
- {
- get { return GetValue(PopupManagerProperty) as PopupManager; }
- set { SetValue(PopupManagerProperty, value); }
- }
-
- ///
- /// Identifies the dependency property.
- ///
- public static readonly DependencyProperty PopupManagerProperty =
- DependencyProperty.Register(nameof(PopupManager), typeof(PopupManager), typeof(PopupViewer),
- new PropertyMetadata(null, OnPopupManagerPropertyChanged));
-
- private static void OnPopupManagerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as PopupViewer)?.Refresh();
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.WindowsXaml.cs b/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.WindowsXaml.cs
deleted file mode 100644
index 2280a05cf..000000000
--- a/src/Toolkit/Toolkit.WinUI/UI/Controls/PopupViewer/PopupViewer.WindowsXaml.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-// /*******************************************************************************
-// * Copyright 2012-2018 Esri
-// *
-// * Licensed under the Apache License, Version 2.0 (the "License");
-// * you may not use this file except in compliance with the License.
-// * You may obtain a copy of the License at
-// *
-// * http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing, software
-// * distributed under the License is distributed on an "AS IS" BASIS,
-// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// * See the License for the specific language governing permissions and
-// * limitations under the License.
-// ******************************************************************************/
-
-#if WINDOWS_XAML
-
-using Esri.ArcGISRuntime.Mapping.Popups;
-
-#if __IOS__
-using Control = UIKit.UIView;
-#elif __ANDROID__
-using Control = Android.Views.ViewGroup;
-#endif
-
-namespace Esri.ArcGISRuntime.Toolkit.UI.Controls
-{
- ///
- /// The PopupViewer control is used to display details and media, edit attributes, geometry and related records,
- /// manage attachments of an or a
- /// as defined in its .
- ///
- public partial class PopupViewer : Control
- {
-#if !__ANDROID__
- ///
- /// Initializes a new instance of the class.
- ///
- public PopupViewer()
- : base()
- {
- Initialize();
- }
-#endif
-
- ///
- /// Gets or sets the associated PopupManager which contains popup and sketch editor.
- ///
- public PopupManager? PopupManager
- {
- get => PopupManagerImpl;
- set => PopupManagerImpl = value;
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/Toolkit/Toolkit/Internal/DispatcherExtensions.cs b/src/Toolkit/Toolkit/Internal/DispatcherExtensions.cs
index ebc946000..15f6a69ba 100644
--- a/src/Toolkit/Toolkit/Internal/DispatcherExtensions.cs
+++ b/src/Toolkit/Toolkit/Internal/DispatcherExtensions.cs
@@ -37,6 +37,23 @@ internal static void Dispatch(this System.Windows.Threading.DispatcherObject dOb
else
dObject.Dispatcher.Invoke(action);
}
+#elif WINUI
+ internal static void Dispatch(this DependencyObject dObject, Action action)
+ {
+ if (dObject.DispatcherQueue.HasThreadAccess)
+ action();
+ else
+ dObject.DispatcherQueue.TryEnqueue(() => action());
+ }
+
+#elif WINDOWS_UWP
+ internal static void Dispatch(this DependencyObject dObject, Action action)
+ {
+ if (dObject.Dispatcher.HasThreadAccess)
+ action();
+ else
+ _ = dObject.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => action());
+ }
#endif
}
}
diff --git a/src/Toolkit/Toolkit/Internal/HtmlUtility.cs b/src/Toolkit/Toolkit/Internal/HtmlUtility.cs
index ed20393ee..a65fecb18 100644
--- a/src/Toolkit/Toolkit/Internal/HtmlUtility.cs
+++ b/src/Toolkit/Toolkit/Internal/HtmlUtility.cs
@@ -1,4 +1,3 @@
-#if WPF || MAUI
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -301,7 +300,11 @@ internal static MarkupNode BuildDocumentTree(string snippet)
else if (name == "font")
{
if (attr.TryGetValue("color", out var fontColor))
+#if WINDOWS_UWP
+ newNode.FontColor = ParseCssColor(fontColor);
+#else
newNode.FontColor = ColorTranslator.FromHtml(fontColor);
+#endif
if (attr.TryGetValue("size", out var fontSizeStr) && Int32.TryParse(fontSizeStr, out var fontSize))
newNode.FontSize = ParseHtmlFontSize(fontSize);
}
@@ -326,7 +329,11 @@ internal static MarkupNode BuildDocumentTree(string snippet)
case "tr":
newNode.Type = MarkupType.TableRow;
if (attr.TryGetValue("bgcolor", out var backColor))
+#if WINDOWS_UWP
+ newNode.BackColor = ParseCssColor(backColor);
+#else
newNode.BackColor = ColorTranslator.FromHtml(backColor);
+#endif
// TODO valign
break;
case "td":
@@ -1141,5 +1148,4 @@ internal enum HtmlAlignment
Right,
Center,
Justify,
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/AttachmentsFormElementView.Windows.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/AttachmentsFormElementView.Windows.cs
index 2ed8abf53..6f8d67464 100644
--- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/AttachmentsFormElementView.Windows.cs
+++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/AttachmentsFormElementView.Windows.cs
@@ -52,7 +52,6 @@ public override void OnApplyTemplate()
}
if(GetTemplateChild("ItemsScrollView") is ScrollViewer scrollViewer)
scrollViewer.ScrollChanged += ScrollViewer_ScrollChanged;
- UpdateVisibility();
}
private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
@@ -88,4 +87,4 @@ private void AddAttachmentButton_Click(object sender, RoutedEventArgs e)
}
}
}
-#endif
+#endif
\ No newline at end of file
diff --git a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentThumbnailImage.cs b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentThumbnailImage.cs
new file mode 100644
index 000000000..121ac7abe
--- /dev/null
+++ b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentThumbnailImage.cs
@@ -0,0 +1,199 @@
+// /*******************************************************************************
+// * Copyright 2012-2018 Esri
+// *
+// * Licensed under the Apache License, Version 2.0 (the "License");
+// * you may not use this file except in compliance with the License.
+// * You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// ******************************************************************************/
+#if WPF || WINDOWS_XAML
+using Esri.ArcGISRuntime.Mapping.Popups;
+using Esri.ArcGISRuntime.Toolkit.Internal;
+using Esri.ArcGISRuntime.UI;
+
+#if NET6_0_OR_GREATER
+using System.IO;
+using System.Runtime.InteropServices.WindowsRuntime;
+#endif
+#if WINUI
+using Microsoft.UI.Xaml.Media.Imaging;
+#elif WINDOWS_UWP
+using Windows.UI.Xaml.Media.Imaging;
+#endif
+
+namespace Esri.ArcGISRuntime.Toolkit.Primitives
+{
+ ///
+ /// Supporting control for the control,
+ /// used for rendering a .
+ ///
+ public class AttachmentThumbnailImage : Control
+ {
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public AttachmentThumbnailImage()
+ {
+ DefaultStyleKey = typeof(AttachmentThumbnailImage);
+ }
+
+ ///
+#if WINDOWS_XAML
+ protected override void OnApplyTemplate()
+#else
+ public override void OnApplyTemplate()
+#endif
+ {
+ base.OnApplyTemplate();
+
+ UpdateVisualState(false);
+ LoadThumbnail();
+ }
+
+ ///
+ /// Gets or sets the attachment to display.
+ ///
+ public PopupAttachment? Attachment
+ {
+ get { return (PopupAttachment)GetValue(AttachmentProperty); }
+ set { SetValue(AttachmentProperty, value); }
+ }
+
+ ///
+ /// Identifies the dependency property.
+ ///
+ public static readonly DependencyProperty AttachmentProperty =
+ DependencyProperty.Register(nameof(Attachment), typeof(PopupAttachment), typeof(AttachmentThumbnailImage), new PropertyMetadata(null, (d, e) => ((AttachmentThumbnailImage)d).OnAttachmentChanged(e.OldValue as PopupAttachment, e.NewValue as PopupAttachment)));
+
+ private void OnAttachmentChanged(PopupAttachment? oldAttachment, PopupAttachment? newAttachment)
+ {
+ var img = GetTemplateChild("PART_Image") as Image;
+ if(img != null)
+ {
+ img.Source = null;
+ }
+ if (oldAttachment != null)
+ {
+ oldAttachment.LoadStatusChanged -= Attachment_LoadStatusChanged;
+ }
+ if (newAttachment != null && newAttachment.LoadStatus != LoadStatus.Loaded)
+ {
+ newAttachment.LoadStatusChanged += Attachment_LoadStatusChanged;
+ }
+ LoadThumbnail();
+ UpdateVisualState(false);
+ }
+
+ private void Attachment_LoadStatusChanged(object? sender, LoadStatusEventArgs e)
+ {
+ if (e.Status == LoadStatus.Loaded)
+ {
+ ((ILoadable)sender!).LoadStatusChanged -= Attachment_LoadStatusChanged;
+ this.Dispatch(LoadThumbnail);
+ }
+ this.Dispatch(() => UpdateVisualState(true));
+ }
+
+ private void UpdateVisualState(bool useTransistions)
+ {
+ var status = Attachment?.LoadStatus ?? LoadStatus.NotLoaded;
+ bool isLocal = Attachment?.IsLocal ?? false;
+ if (isLocal)
+ VisualStateManager.GoToState(this, "AttachmentIsLocal", useTransistions);
+ else
+ {
+ switch (status)
+ {
+ case LoadStatus.Loading:
+ VisualStateManager.GoToState(this, "AttachmentLoading", useTransistions);
+ break;
+ case LoadStatus.Loaded:
+ VisualStateManager.GoToState(this, "AttachmentLoaded", useTransistions);
+ break;
+ case LoadStatus.FailedToLoad:
+ VisualStateManager.GoToState(this, "AttachmentFailedToLoad", useTransistions);
+ break;
+ case LoadStatus.NotLoaded:
+ VisualStateManager.GoToState(this, "AttachmentNotLoaded", useTransistions);
+ break;
+ }
+ }
+ }
+
+ private async void LoadThumbnail()
+ {
+ var img = GetTemplateChild("PART_Image") as Image;
+ if (img is null || ThumbnailSize <= 0)
+ return;
+ try
+ {
+#if WINUI
+ var size = ThumbnailSize * XamlRoot?.RasterizationScale ?? 1;
+#elif WINDOWS_UWP
+ var size = ThumbnailSize * Windows.Graphics.Display.DisplayInformation.GetForCurrentView()?.RawPixelsPerViewPixel ?? 1;
+#elif WPF
+ var size = ThumbnailSize * VisualTreeHelper.GetDpi(this).PixelsPerDip;
+#endif
+#if NETFRAMEWORK
+ if (Attachment != null && Attachment.Type == PopupAttachmentType.Image && Attachment.IsLocal)
+ {
+ var thumb = await Attachment.CreateThumbnailAsync((int)size, (int)size);
+ img.Source = await thumb.ToImageSourceAsync();
+ return;
+ }
+#else
+ if (Attachment != null && Attachment.IsLocal)
+ {
+ if (!File.Exists(Attachment.Filename) && Attachment.LoadStatus == LoadStatus.NotLoaded)
+ {
+ await Attachment.LoadAsync();
+ }
+ if (File.Exists(Attachment.Filename))
+ {
+ var fs = await Windows.Storage.StorageFile.GetFileFromPathAsync(Attachment.Filename);
+
+ var thumb = await fs.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, (uint)size, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);
+ using var ms = new MemoryStream();
+ thumb.AsStreamForRead().CopyTo(ms);
+ ms.Seek(0, SeekOrigin.Begin);
+#if WPF
+ img.Source = System.Windows.Media.Imaging.BitmapFrame.Create(ms, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);
+#else
+ var source = new BitmapImage();
+ await source.SetSourceAsync(ms.AsRandomAccessStream());
+ img.Source = source;
+#endif
+ return;
+ }
+ }
+#endif
+ }
+ catch { }
+ img.Source = null;
+ }
+
+ ///
+ /// Gets or sets the size of the thumbnail to display.
+ ///
+ public double ThumbnailSize
+ {
+ get { return (double)GetValue(ThumbnailSizeProperty); }
+ set { SetValue(ThumbnailSizeProperty, value); }
+ }
+
+ ///
+ /// Identifies the dependency property.
+ ///
+ public static readonly DependencyProperty ThumbnailSizeProperty =
+ DependencyProperty.Register(nameof(ThumbnailSize), typeof(double), typeof(AttachmentThumbnailImage), new PropertyMetadata(30d));
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.Windows.cs b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.Windows.cs
index 9a9f5c895..d6f625a69 100644
--- a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.Windows.cs
+++ b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.Windows.cs
@@ -14,10 +14,15 @@
// * limitations under the License.
// ******************************************************************************/
-#if WPF
+#if WPF || WINDOWS_XAML
using Esri.ArcGISRuntime.Mapping.Popups;
-using Microsoft.Win32;
-using System.Windows.Controls.Primitives;
+using Esri.ArcGISRuntime.UI;
+using System.IO;
+
+#if NET6_0_OR_GREATER
+using System.Runtime.InteropServices.WindowsRuntime;
+
+#endif
namespace Esri.ArcGISRuntime.Toolkit.Primitives
{
diff --git a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.cs b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.cs
index 3b9a17405..6edfd7f8d 100644
--- a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.cs
+++ b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.cs
@@ -14,13 +14,12 @@
// * limitations under the License.
// ******************************************************************************/
-#if WPF || MAUI
using Esri.ArcGISRuntime.Mapping.Popups;
using Esri.ArcGISRuntime.Toolkit.Internal;
using Microsoft.Win32;
#if WPF
using System.Windows.Controls.Primitives;
-#else
+#elif MAUI
using ListBox = Microsoft.Maui.Controls.CollectionView;
using Selector = Microsoft.Maui.Controls.SelectableItemsView;
#endif
@@ -46,9 +45,9 @@ public AttachmentsPopupElementView()
}
///
-#if MAUI
+#if WINDOWS_XAML || MAUI
protected override void OnApplyTemplate()
-#else
+#elif WPF
public override void OnApplyTemplate()
#endif
{
@@ -157,7 +156,7 @@ await Microsoft.Maui.ApplicationModel.Launcher.Default.OpenAsync(
{
System.Diagnostics.Trace.WriteLine($"Failed to open attachment: " + ex.Message);
}
-#else
+#elif WPF
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = attachment.Name;
if (saveFileDialog.ShowDialog() == true)
@@ -173,9 +172,45 @@ await Microsoft.Maui.ApplicationModel.Launcher.Default.OpenAsync(
System.Diagnostics.Trace.WriteLine($"Failed to save file to disk: " + ex.Message);
}
}
+#elif WINDOWS_XAML
+ Windows.Storage.StorageFile? file = null;
+#if WINUI
+ var hwnd = this.XamlRoot?.ContentIslandEnvironment?.AppWindowId.Value ?? 0;
+ if (hwnd == 0)
+ return; // Can't show dialog without a root window
+#endif
+ try
+ {
+ if (attachment.LoadStatus == LoadStatus.NotLoaded)
+ await attachment.LoadAsync();
+ var fileInfo = new FileInfo(attachment.Filename!);
+ var savePicker = new Windows.Storage.Pickers.FileSavePicker();
+#if WINUI
+ WinRT.Interop.InitializeWithWindow.Initialize(savePicker, (nint)hwnd);
+#endif
+ var ext = fileInfo.Extension;
+ savePicker.FileTypeChoices.Add("*" + ext, new List() { ext });
+ savePicker.SuggestedFileName = fileInfo.Name;
+ file = await savePicker.PickSaveFileAsync();
+ if (file != null)
+ {
+ Windows.Storage.CachedFileManager.DeferUpdates(file);
+ using var stream = await attachment.Attachment!.GetDataAsync();
+ using var filestream= await file.OpenStreamForWriteAsync();
+ await stream.CopyToAsync(filestream);
+ }
+ }
+ catch (System.Exception ex)
+ {
+ System.Diagnostics.Trace.WriteLine($"Failed to open attachment: " + ex.Message);
+ }
+ finally
+ {
+ if (file != null)
+ _ = Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);
+ }
#endif
}
}
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.Windows.cs b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.Windows.cs
index c8d2de74a..7aa3169d8 100644
--- a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.Windows.cs
+++ b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.Windows.cs
@@ -14,11 +14,13 @@
// * limitations under the License.
// ******************************************************************************/
-#if WPF
+#if WPF || WINDOWS_XAML
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping.Popups;
using Esri.ArcGISRuntime.Toolkit.Internal;
+#if WPF
using System.Windows.Documents;
+#endif
namespace Esri.ArcGISRuntime.Toolkit.Primitives
{
diff --git a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.cs b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.cs
index b9a0af058..1ed22b48c 100644
--- a/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.cs
+++ b/src/Toolkit/Toolkit/UI/Controls/PopupViewer/FieldsPopupElementView.cs
@@ -14,7 +14,6 @@
// * limitations under the License.
// ******************************************************************************/
-#if WPF || MAUI
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping.Popups;
using Esri.ArcGISRuntime.Toolkit.Internal;
@@ -24,11 +23,17 @@
using Esri.ArcGISRuntime.Toolkit.UI.Controls;
#endif
+
#if MAUI
using TextBlock = Microsoft.Maui.Controls.Label;
-#else
+#elif WPF
using System.Windows.Documents;
+#elif WINUI
+using Microsoft.UI.Xaml.Documents;
+#elif WINDOWS_UWP
+using Windows.UI.Xaml.Documents;
#endif
+
#if MAUI
namespace Esri.ArcGISRuntime.Toolkit.Maui.Primitives
#else
@@ -56,9 +61,9 @@ public FieldsPopupElementView()
///
#if WINDOWS_XAML || MAUI
protected override void OnApplyTemplate()
-#else
+#elif WPF
public override void OnApplyTemplate()
-# endif
+#endif
{
base.OnApplyTemplate();
RefreshTable();
@@ -77,7 +82,7 @@ public FieldsPopupElement? Element
/// Identifies the dependency property.
///
public static readonly DependencyProperty ElementProperty =
- PropertyHelper.CreateProperty(nameof(Element), null, (s, oldValue, newValue) => s.RefreshTable());
+ PropertyHelper.CreateProperty(nameof(Element), null, (s, oldValue, newValue) => s.RefreshTable());
private void RefreshTable()
{
@@ -152,7 +157,11 @@ private void RefreshTable()
if (uri is not null)
PopupViewer.GetPopupViewerParent(this)?.OnHyperlinkClicked(uri);
};
+#if WINDOWS_XAML
+ hl.Inlines.Add(new Run() { Text = "View" });
+#else
hl.Inlines.Add("View");
+#endif
t.Inlines.Add(hl);
#endif
}
@@ -239,5 +248,4 @@ public Style FieldTextStyle
public static readonly DependencyProperty FieldTextStyleProperty =
PropertyHelper.CreateProperty