Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net10.0-android;net10.0-ios;net10.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net10.0-windows10.0.19041.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>SampleBrowser.Maui.PdfViewer</RootNamespace>
<UseMaui>true</UseMaui>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public partial class Annotations : SampleView
/// </summary>
bool undoAlreadyExecuted = false;
#if ANDROID || IOS
private ViewCell? lastCell;
private View? lastCell;
#endif
public Stream CustomStampImageStream { get; set; } = new MemoryStream();
public double CustomStampWidth { get; set; }
Expand Down Expand Up @@ -411,7 +411,11 @@ async void ShowToast(string text)
toast.Opacity = 1;
toastText.Text = text;
toast.InputTransparent = true;
#if NET10_0_OR_GREATER
await toast.FadeToAsync(0, 2000, Easing.SinIn);
#else
await toast.FadeTo(0, 2000, Easing.SinIn);
#endif
}

private void UndoCommand_CanExecuteChanged(object? sender, EventArgs e)
Expand Down Expand Up @@ -628,12 +632,11 @@ private void ViewCell_Tapped(object sender, EventArgs e)
{
#if ANDROID || IOS
if (lastCell != null)
lastCell.View.BackgroundColor = Colors.Transparent;
var viewCell = (ViewCell)sender;
if (viewCell.View != null)
lastCell.BackgroundColor = Colors.Transparent;
if (sender is View tappedView)
{
viewCell.View.BackgroundColor = Color.FromArgb("#0A000000");
lastCell = viewCell;
tappedView.BackgroundColor = Color.FromArgb("#0A000000");
lastCell = tappedView;
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace SampleBrowser.Maui.PdfViewer.SfPdfViewer
{
internal class ImageSignatureCreateView : SfView, ISignatureCreateView
{
string? imageFilePath;
string? imageFilePath = String.Empty;
Stream? imageStream;

private static readonly BindableProperty SignatureUploadButtonColorProperty = BindableProperty.Create("SignatureUploadButtonColor", typeof(Color), typeof(ImageSignatureCreateView), defaultValue: Color.FromArgb("#6750A4"));
Expand Down Expand Up @@ -158,6 +158,44 @@ private async void Element_Drop(object sender, Microsoft.UI.Xaml.DragEventArgs e

private async void UploadButton_Clicked(object? sender, System.EventArgs e)
{
#if (ANDROID || WINDOWS) && NET10_0_OR_GREATER
var imageFileResults = await MediaPicker.Default.PickPhotosAsync(new MediaPickerOptions
{
Title = "Select a photo"
});
if (imageFileResults != null)
{
// If you just want the first photo
var imageFileResult = imageFileResults.FirstOrDefault();
if (imageFileResult != null)
{
imageStream = await imageFileResult.OpenReadAsync();
imageFilePath = imageFileResult.FullPath;
if (BindingContext is SignatureViewModel viewModel)
{
viewModel.UploadTabImageSource = new FileImageSource
{
File = imageFilePath
};
}
}
}
#elif !ANDROID && !WINDOWS && NET10_0_OR_GREATER
var file = await MediaPicker.PickPhotosAsync();
if (file.Count > 0 && file[0] is FileResult _file)
{
imageStream = await _file.OpenReadAsync();
Stream copiedImageStream = new MemoryStream();
imageStream.CopyTo(copiedImageStream);
copiedImageStream.Position = 0;
if (imageStream != null)
{
if (BindingContext is SignatureViewModel viewModel)
viewModel.UploadTabImageSource = ImageSource.FromStream(() => copiedImageStream);
}

}
#else
FileResult? imageFileResult = await MediaPicker.Default.PickPhotoAsync();
if (imageFileResult != null)
{
Expand All @@ -169,6 +207,7 @@ private async void UploadButton_Clicked(object? sender, System.EventArgs e)
File = imageFilePath,
};
}
#endif
}

void ISignatureCreateView.Reset()
Expand All @@ -185,6 +224,12 @@ SignatureItem ISignatureCreateView.GetSignatureItem()
HorizontalOptions = LayoutOptions.Center,
Source = new FileImageSource { File = imageFilePath }
};

if (!string.IsNullOrEmpty(imageFilePath))
image.Source = new FileImageSource { File = imageFilePath };
else if (imageStream != null)
image.Source = ImageSource.FromStream(() => { return imageStream; });

ImageSignatureItem signatureItem = new ImageSignatureItem(imageStream, imageFilePath, image);
return signatureItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ private void AddSignatureListview()
ListView.ScrollBarVisibility = ScrollBarVisibility.Default;
ListView.ItemTemplate = new DataTemplate(() =>
{
ViewCell view = new ViewCell();

SignatureListItemView grid = new SignatureListItemView();
grid.DeleteClicked += Grid_DeleteClicked;
#if NET10_0_OR_GREATER
return grid;
#else
ViewCell view = new ViewCell();
view.View = grid;

return view;
#endif
});
Grid.SetRow(ListView, 0);
mainGrid?.Children?.Add(ListView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,20 @@ SfListView CreateSignatureListview()
listView.ScrollBarVisibility = ScrollBarVisibility.Default;
listView.ItemTemplate = new DataTemplate(() =>
{
ViewCell view = new ViewCell();

SignatureListBorder border = new SignatureListBorder();
border.LongPressed += ListBorder_LongPressed;
border.Tapped += ListBorder_Tapped;
ContentView image = new ContentView();
image.SetBinding(ContentView.ContentProperty, new Binding("View"));
border.Content = image;
#if NET10_0_OR_GREATER
return border;
#else
ViewCell view = new ViewCell();
view.View = border;

return view;
#endif
});
return listView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<local:StampView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:DataType="local:StampsData"
xmlns:local="clr-namespace:SampleBrowser.Maui.PdfViewer.SfPdfViewer"
xmlns:listView="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView"
x:Class="SampleBrowser.Maui.PdfViewer.SfPdfViewer.StampViewDesktop"
PropertyChanged="StampMenu_PropertyChanged">

Expand All @@ -23,14 +24,14 @@
BackgroundColor="{AppThemeBinding Light={StaticResource SampleBrowserBackgroundLight}, Dark={StaticResource BackgroundDark},Default=#EEE8F4}"
PropertyChanged="StandardStampMenu_PropertyChanged"
Stroke="#33000000" HeightRequest="500" WidthRequest="280" VerticalOptions="End">
<ListView RowHeight="44" BackgroundColor="{AppThemeBinding Light={StaticResource SampleBrowserBackgroundLight}, Dark={StaticResource BackgroundDark},Default=#EEE8F4}" Margin="0,8"
<listView:SfListView ItemSize="44" BackgroundColor="{AppThemeBinding Light={StaticResource SampleBrowserBackgroundLight}, Dark={StaticResource BackgroundDark},Default=#EEE8F4}" Margin="0,8"
ItemsSource="{Binding StandardStampItems}"
x:Name="StandardStampMenuItems"
ItemTapped="Stamp_ItemTapped"
SelectionMode="None">
<ListView.ItemTemplate>
<listView:SfListView.ItemTemplate>
<DataTemplate x:DataType="local:StandardStamps">
<ViewCell>
<Grid>
<StackLayout HorizontalOptions="Start" WidthRequest="280" Padding="0,5,0,7">
<Border Margin="7,0,19,0" HorizontalOptions="Start" Stroke="{Binding BorderColor}" HeightRequest="{Binding BorderHeight}" WidthRequest="{Binding BorderWidth}"
Background="{Binding BorderBackground}" StrokeThickness="2"
Expand All @@ -57,10 +58,10 @@
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
</StackLayout>
</ViewCell>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</listView:SfListView.ItemTemplate>
</listView:SfListView>
</Border>
<Grid Margin="0,5,0,0" x:Name="CustomStampMenu" IsVisible="false"
HorizontalOptions="Start" VerticalOptions="Start" MaximumHeightRequest="500" WidthRequest="200">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ private void StandardStampMenu_PropertyChanged(object sender, System.ComponentMo
}
}

private void Stamp_ItemTapped(object sender, Microsoft.Maui.Controls.ItemTappedEventArgs e)
private void Stamp_ItemTapped(object sender, Syncfusion.Maui.ListView.ItemTappedEventArgs e)
{
if (StampHelper != null)
{
if (e.Item is StandardStamps standardStamp && standardStamp.LabelText != null)
if (e.DataItem is StandardStamps standardStamp && standardStamp.LabelText != null)
{
stampType = GetStampType(standardStamp.LabelText);
StampMode = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
using SampleBrowser.Maui.Base;
using Syncfusion.Maui.Core.Internals;
using Syncfusion.Maui.PdfViewer;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using System.IO;
using System.Reflection;
using Syncfusion.Maui.Core.Converters;

namespace SampleBrowser.Maui.PdfViewer.SfPdfViewer;
[XamlCompilation(XamlCompilationOptions.Compile)]
Expand All @@ -31,7 +30,11 @@ public partial class CustomToolbar : SampleView
/// </summary>
bool undoAlreadyExecuted = false;
#if ANDROID || IOS
#if NET10_0_OR_GREATER
private View? lastCell;
#else
private ViewCell? lastCell;
#endif
#endif
public Stream CustomStampImageStream { get; set; } = new MemoryStream();
public double CustomStampWidth { get; set; }
Expand Down Expand Up @@ -404,7 +407,11 @@ async void ShowToast(string text)
{
toast.Opacity = 1;
toastText.Text = text;
#if NET10_0_OR_GREATER
await toast.FadeToAsync(0, 2000, Easing.SinIn);
#else
await toast.FadeTo(0, 2000, Easing.SinIn);
#endif
}

private void UndoCommand_CanExecuteChanged(object? sender, EventArgs e)
Expand Down Expand Up @@ -735,14 +742,24 @@ private void PdfViewer_DocumentLoadFailed(object sender, DocumentLoadFailedEvent
private void ViewCell_Tapped(object sender, EventArgs e)
{
#if ANDROID || IOS
#if NET10_0_OR_GREATER
if (lastCell != null)
lastCell.BackgroundColor = Colors.Transparent;
if (sender is View tappedView)
{
tappedView.BackgroundColor = Color.FromArgb("#0A000000");
lastCell = tappedView;
}
#else
if (lastCell != null)
lastCell.View.BackgroundColor = Colors.Transparent;
var viewCell = (ViewCell)sender;
if (viewCell.View != null)
{
viewCell.View.BackgroundColor = Color.FromArgb("#0A000000");
lastCell = viewCell;
}
#endif
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4172,12 +4172,20 @@ internal async void SaveDocument()
if (FileData != null && FileData.FileName != null)
{
string? filePath = await FileService.SaveAsAsync(FileData.FileName, outStream);
#if NET10_0_OR_GREATER
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("File saved", $"The file is saved to {filePath}", "OK");
#else
await Application.Current!.Windows[0].Page!.DisplayAlert("File saved", $"The file is saved to {filePath}", "OK");
#endif
}
}
catch (Exception exception)
{
#if NET10_0_OR_GREATER
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("Error", $"The file is not saved. {exception.Message}", "OK");
#else
await Application.Current!.Windows[0].Page!.DisplayAlert("Error", $"The file is not saved. {exception.Message}", "OK");
#endif
}
}

Expand All @@ -4204,7 +4212,11 @@ internal async void ImportAnnotations()
}
catch (Exception exception)
{
#if NET10_0_OR_GREATER
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("Error", $"The file is not imported. {exception.Message}", "OK");
#else
await Application.Current!.Windows[0].Page!.DisplayAlert("Error", $"The file is not imported. {exception.Message}", "OK");
#endif
}
}
}
Expand Down Expand Up @@ -4235,12 +4247,20 @@ internal async void ExportAnnotations()
{
string exportedPdfFileName = FileData.FileName.Replace(".pdf", ".xfdf");
string? filePath = await FileService.SaveAsAsync(exportedPdfFileName, outStream);
#if NET10_0_OR_GREATER
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("File saved", $"The file is saved to {filePath}", "OK");
#else
await Application.Current!.Windows[0].Page!.DisplayAlert("File saved", $"The file is saved to {filePath}", "OK");
#endif
}
}
catch (Exception exception)
{
#if NET10_0_OR_GREATER
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("Error", $"The file is not saved. {exception.Message}", "OK");
#else
await Application.Current!.Windows[0].Page!.DisplayAlert("Error", $"The file is not saved. {exception.Message}", "OK");
#endif
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public partial class FileService
return new PdfFileData(result.FileName, await result.OpenReadAsync());
}
else
{
#if NET10_0_OR_GREATER
Application.Current?.Windows[0].Page?.DisplayAlertAsync("Error", $"Pick a file of type {fileExtension}", "OK");
#else
Application.Current?.Windows[0].Page?.DisplayAlert("Error", $"Pick a file of type {fileExtension}", "OK");
#endif
}
}
}
return null;
Expand All @@ -69,7 +75,11 @@ public partial class FileService
message = ex.Message;
else
message = "File open failed.";
#if NET10_0_OR_GREATER
Application.Current?.Windows[0].Page?.DisplayAlertAsync("Error", message, "OK");
#else
Application.Current?.Windows[0].Page?.DisplayAlert("Error", message, "OK");
#endif
}
return null;
}
Expand Down
Loading