gene
2 years ago
7 changed files with 101 additions and 55 deletions
-
BINCircleViewer/.vs/CircleViewer/v17/.suo
-
8CircleViewerMaui/App.xaml.cs
-
1CircleViewerMaui/AppShell.xaml
-
8CircleViewerMaui/CircleViewerMaui.csproj
-
49CircleViewerMaui/MainPage.xaml
-
79CircleViewerMaui/MainPage.xaml.cs
-
11CircleViewerMaui/MauiProgram.cs
@ -1,45 +1,16 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
|||
xmlns:pdfViewer="http://schemas.syncfusion.com/maui" |
|||
x:Class="CircleViewerMaui.MainPage"> |
|||
|
|||
<ScrollView> |
|||
<ScrollView.GestureRecognizers> |
|||
<DragGestureRecognizer /> |
|||
<DropGestureRecognizer /> |
|||
</ScrollView.GestureRecognizers> |
|||
<VerticalStackLayout |
|||
Spacing="25" |
|||
Padding="30,0" |
|||
VerticalOptions="Center"> |
|||
|
|||
<Image |
|||
Source="dotnet_bot.png" |
|||
SemanticProperties.Description="Cute dot net bot waving hi to you!" |
|||
HeightRequest="200" |
|||
HorizontalOptions="Center" /> |
|||
|
|||
<Label |
|||
Text="Hello, World!" |
|||
SemanticProperties.HeadingLevel="Level1" |
|||
FontSize="32" |
|||
HorizontalOptions="Center" /> |
|||
|
|||
<Label |
|||
Text="Welcome to .NET Multi-platform App UI" |
|||
SemanticProperties.HeadingLevel="Level2" |
|||
SemanticProperties.Description="Welcome to dot net Multi platform App U I" |
|||
FontSize="18" |
|||
HorizontalOptions="Center" /> |
|||
|
|||
<Button |
|||
x:Name="CounterBtn" |
|||
Text="Click me" |
|||
SemanticProperties.Hint="Counts the number of times you click" |
|||
Clicked="OnCounterClicked" |
|||
HorizontalOptions="Center" /> |
|||
|
|||
</VerticalStackLayout> |
|||
</ScrollView> |
|||
|
|||
<ContentPage.MenuBarItems> |
|||
<MenuBarItem Text="File"> |
|||
<MenuFlyoutItem Text="Open" Clicked="onOpenClicked"/> |
|||
</MenuBarItem> |
|||
</ContentPage.MenuBarItems> |
|||
<ContentPage.Content> |
|||
<pdfViewer:SfPdfViewer x:Name="PdfViewer" VerticalOptions="Fill"> |
|||
</pdfViewer:SfPdfViewer> |
|||
</ContentPage.Content> |
|||
</ContentPage> |
@ -1,32 +1,89 @@ |
|||
using System.Reflection; |
|||
using CDPShared; |
|||
using Syncfusion.Maui.PdfViewer; |
|||
|
|||
namespace CircleViewerMaui; |
|||
|
|||
public partial class MainPage : ContentPage |
|||
{ |
|||
int count = 0; |
|||
int count = 0; |
|||
private CDPWorker _cdp; |
|||
Timer _timer; |
|||
Boolean _bConnected = false; |
|||
|
|||
public MainPage() |
|||
{ |
|||
{ |
|||
using (LogMethod.Log(MethodBase.GetCurrentMethod().ReflectedType.Name)) |
|||
{ |
|||
_cdp = new CDPWorker(); |
|||
InitializeComponent(); |
|||
_timer = new Timer(IsReady, null, 250, 250); |
|||
|
|||
} |
|||
} |
|||
|
|||
void IsReady(object state) |
|||
{ |
|||
if (_bConnected != _cdp.Ready) |
|||
{ |
|||
_bConnected = _cdp.Ready; |
|||
OnReady(); |
|||
_timer = null; |
|||
} |
|||
} |
|||
|
|||
private void OnCounterClicked(object sender, EventArgs e) |
|||
{ |
|||
count++; |
|||
void OnReady() |
|||
{ |
|||
// Device.InvokeOnMainThreadAsync(() => { lblConnected.Text = "Connected"; });
|
|||
} |
|||
|
|||
public async Task<string> OpenCirFileAsync() |
|||
{ |
|||
var fileTypes = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>> |
|||
{ |
|||
{ DevicePlatform.iOS, new[] { "public.cir" } }, |
|||
{ DevicePlatform.Android, new[] { "application/cir" } }, |
|||
{ DevicePlatform.WinUI, new[] { ".cir" } }, |
|||
{ DevicePlatform.macOS, new[] { ".cir" } } |
|||
}); |
|||
|
|||
var options = new PickOptions |
|||
{ |
|||
FileTypes = fileTypes, |
|||
PickerTitle = "Open .cir File" |
|||
}; |
|||
|
|||
if (count == 1) |
|||
CounterBtn.Text = $"Clicked {count} time"; |
|||
else |
|||
CounterBtn.Text = $"Clicked {count} times"; |
|||
var result = await FilePicker.PickAsync(options); |
|||
|
|||
SemanticScreenReader.Announce(CounterBtn.Text); |
|||
} |
|||
if (result != null) |
|||
{ |
|||
return result.FullPath; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private async void onOpenClicked(object sender, EventArgs e) |
|||
{ |
|||
var filePath = await OpenCirFileAsync(); |
|||
if (filePath != null) |
|||
{ |
|||
ViewFileAsync(filePath); |
|||
} |
|||
} |
|||
|
|||
async void ViewFileAsync(string fileToLoad) |
|||
{ |
|||
using (LogMethod.Log(MethodBase.GetCurrentMethod().ReflectedType.Name)) |
|||
{ |
|||
var result = await _cdp.Decrypt(fileToLoad); |
|||
if (result.Status.Result.GetValueOrDefault(false)) |
|||
{ |
|||
byte[] buf = Convert.FromBase64String(result.DecryptedData); |
|||
string ext = Path.GetExtension(result.FileName); |
|||
PdfViewer.DocumentSource = new MemoryStream(buf); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue