Skip to content

Commit

Permalink
PopupViewer WinUI/UWP (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotMorten authored Aug 5, 2024
1 parent e36b7f3 commit 5bef801
Show file tree
Hide file tree
Showing 25 changed files with 1,176 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
GeoViewTapped="mapView_GeoViewTapped"/>
<toolkit:PopupViewer x:Name="popupViewer"
Grid.Column="1"
Padding="5"
Padding="10"
Width="300"
Visibility="Collapsed"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
VerticalAlignment="Stretch"
PopupAttachmentClicked="popupViewer_PopupAttachmentClicked"
HyperlinkClicked="popupViewer_LinkClicked" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -116,5 +113,45 @@ private Mapping.Popups.Popup GetPopup(IEnumerable<IdentifyLayerResult> 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);
}
}
}
111 changes: 65 additions & 46 deletions src/Toolkit/Toolkit.WPF/UI/Controls/PopupViewer/PopupViewer.Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,62 +52,81 @@
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type primitives:AttachmentThumbnailImage}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type primitives:AttachmentThumbnailImage}">
<StackPanel Orientation="Horizontal">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LoadedStates">
<VisualState x:Name="AttachmentLoading">
<Storyboard RepeatBehavior="Forever" >
<DoubleAnimation
Storyboard.TargetName="Icon"
Storyboard.TargetProperty="RenderTransform.Angle"
Duration="0:0:1" From="0" To="360" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon" Storyboard.TargetProperty="Text">
<DiscreteObjectKeyFrame KeyTime="0" Value="&#xE72C;"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="AttachmentLoaded">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon" Storyboard.TargetProperty="Text">
<DiscreteObjectKeyFrame KeyTime="0" Value="&#xF13E;"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="AttachmentFailedToLoad">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon" Storyboard.TargetProperty="Text">
<DiscreteObjectKeyFrame KeyTime="0" Value="&#xEA6A;"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="NotLoaded">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon" Storyboard.TargetProperty="Text">
<DiscreteObjectKeyFrame KeyTime="0" Value="&#xE896;"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="AttachmentIsLocal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon" Storyboard.TargetProperty="Text">
<DiscreteObjectKeyFrame KeyTime="0" Value=""/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Width="{TemplateBinding ThumbnailSize}" Height="{TemplateBinding ThumbnailSize}">
<TextBlock x:Name="Icon" FontFamily="Segoe MDL2 Assets" FontSize="18" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,5,0" Text="&#xE896;" RenderTransformOrigin=".5,.5">
<TextBlock.RenderTransform>
<RotateTransform />
</TextBlock.RenderTransform>
</TextBlock>
<Image x:Name="PART_Image" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<TextBlock Text="{Binding Name}" Margin="5" Cursor="Hand"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type primitives:AttachmentsPopupElementView}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type primitives:AttachmentsPopupElementView}">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="TextBlock" x:Key="DownloadIcon" xmlns:es="clr-namespace:Esri.ArcGISRuntime;assembly=Esri.ArcGISRuntime">
<Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
<Setter Property="FontSize" Value="18" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0,0,5,0" />
<Setter Property="Text" Value="&#xF13E;" />
<Setter Property="RenderTransformOrigin" Value=".5,.5" />
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform />
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding LoadStatus}" Value="{x:Static es:LoadStatus.Loading}">
<Setter Property="Text" Value="&#xE72C;"/>
<Setter Property="ToolTip" Value="Downloading"/>
<DataTrigger.EnterActions>
<BeginStoryboard Name="SpinnerStoryboard">
<Storyboard RepeatBehavior="Forever" >
<DoubleAnimation
Storyboard.TargetProperty="RenderTransform.Angle"
Duration="0:0:1" From="0" To="360" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="SpinnerStoryboard" />
</DataTrigger.ExitActions>
</DataTrigger>
<DataTrigger Binding="{Binding LoadStatus}" Value="{x:Static es:LoadStatus.NotLoaded}">
<Setter Property="Text" Value="&#xE896;"/>
</DataTrigger>
<DataTrigger Binding="{Binding LoadStatus}" Value="{x:Static es:LoadStatus.FailedToLoad}">
<Setter Property="Text" Value="&#xEA6A;"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsLocal}" Value="true">
<Setter Property="Text" Value="&#xF13E;"/>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<TextBlock Text="{Binding Title, Mode=OneWay}" Style="{StaticResource PopupViewerTitleStyle}" Visibility="{Binding Title, Converter={StaticResource PopupViewerVisibilityConverter}}" />
<TextBlock Text="{Binding Description, Mode=OneWay}" Style="{StaticResource PopupViewerCaptionStyle}" Visibility="{Binding Description, Converter={StaticResource PopupViewerVisibilityConverter}}" />
<ListView x:Name="AttachmentList" BorderThickness="0" SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource DownloadIcon}"/>
<TextBlock Text="{Binding Name}" Margin="5" Cursor="Hand"/>
</StackPanel>
<primitives:AttachmentThumbnailImage Attachment="{Binding}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<ItemGroup>
<PackageReference Include="Esri.ArcGISRuntime.WinUI" Version="$(ArcGISRuntimePackageVersion)" Condition="Exists('$(SolutionDir)toolkit.props')!='true'"/>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.230822000" />
</ItemGroup>

<Import Project="..\Toolkit\Esri.ArcGISRuntime.Toolkit.Shared.projitems" Label="Shared" />
Expand Down
Loading

0 comments on commit 5bef801

Please sign in to comment.