Skip to content

Commit

Permalink
windows DisconnectHandler test
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-vov committed Dec 18, 2024
1 parent fffb5e4 commit 4941d66
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 23 deletions.
41 changes: 24 additions & 17 deletions Example/Business/UI/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pdf="clr-namespace:Maui.PDFView;assembly=Maui.PDFView"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Title="Example">
Title="Example"
Unloaded="ContentPage_Unloaded">

<ContentPage.Behaviors>
<toolkit:EventToCommandBehavior
Command="{Binding AppearingCommand}"
EventName="Appearing" />
<toolkit:EventToCommandBehavior Command="{Binding AppearingCommand}" EventName="Appearing" />
</ContentPage.Behaviors>

<Grid RowDefinitions="Auto,*">

<Grid
RowDefinitions="Auto,Auto"
ColumnDefinitions="Auto,Auto,Auto"
ColumnSpacing="8">
ColumnDefinitions="Auto,Auto,Auto,Auto"
ColumnSpacing="8"
RowDefinitions="Auto,Auto">

<Label
Grid.Row="0"
Grid.Column="0"
Text="Horizontal"
FontSize="Caption"
HorizontalTextAlignment="Center"
Text="Horizontal"
VerticalOptions="Center" />

<CheckBox
Expand All @@ -40,33 +39,41 @@
Grid.Column="1"
FontSize="Caption"
HorizontalTextAlignment="Center"
Text="{Binding MaxZoom, StringFormat='Max zoom is {0}'}">
</Label>
Text="{Binding MaxZoom, StringFormat='Max zoom is {0}'}" />

<Stepper
Grid.Row="1"
Grid.Column="1"
Minimum="1"
Maximum="5"
Value="{Binding MaxZoom}"/>
Minimum="1"
Value="{Binding MaxZoom}" />


<Button
Grid.Row="0"
Grid.Column="2"
Grid.RowSpan="2"
VerticalOptions="Center"
Grid.Column="2"
Command="{Binding ChangeUriCommand}"
Text="ChangeUri" />
Text="ChangeUri"
VerticalOptions="Center" />

<Button
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="3"
Command="{Binding OpenNewPageCommand}"
Text="Open new page"
VerticalOptions="Center" />

</Grid>

<pdf:PdfView
x:Name="pdfView"
Grid.Row="1"
IsHorizontal="{Binding IsHorizontal}"
Uri="{Binding PdfSource}"
MaxZoom="{Binding MaxZoom}"
PageChangedCommand="{Binding PageChangedCommand}"/>
PageChangedCommand="{Binding PageChangedCommand}"
Uri="{Binding PdfSource}" />
</Grid>

</ContentPage>
6 changes: 6 additions & 0 deletions Example/Business/UI/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public MainPage()
InitializeComponent();
BindingContext = new MainPageViewModel();
}

private void ContentPage_Unloaded(object sender, EventArgs e)
{
pdfView.Handler?.DisconnectHandler();
}

}
6 changes: 6 additions & 0 deletions Example/Business/UI/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Example.Business.Services;
using Example.Business.UI.Pages;
using Maui.PDFView.Events;
using System.Diagnostics;
using System.Windows.Input;
Expand Down Expand Up @@ -29,5 +30,10 @@ [RelayCommand] private void PageChanged(PageChangedEventArgs args)
{
Debug.WriteLine($"Current page: {args.CurrentPage} of {args.TotalPages}");
}

[RelayCommand] private void OpenNewPage()
{
App.Current.MainPage.Navigation.PushAsync(new MainPage());
}
}
}
2 changes: 2 additions & 0 deletions Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<WindowsPackageType Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
Expand Down
2 changes: 1 addition & 1 deletion Example/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"Windows Machine": {
"commandName": "MsixPackage",
"commandName": "Project",
"nativeDebugging": false
}
}
Expand Down
4 changes: 2 additions & 2 deletions Maui.PDFView/Maui.PDFView.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
Expand All @@ -21,7 +21,7 @@
<Description>MAUI library for displaying PDF files</Description>
<PackageProjectUrl>https://github.com/vitalii-vov/Maui.PDFView</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>1.0.6</Version>
<Version>1.0.7-alpha</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
15 changes: 12 additions & 3 deletions Maui.PDFView/Platforms/Windows/PdfViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,24 @@ protected override ScrollViewer CreatePlatformView()
VerticalScrollBarVisibility = Microsoft.UI.Xaml.Controls.ScrollBarVisibility.Visible,
};

// Attach scroll event to track page changes
_scrollViewer.ViewChanged += OnScrollViewerViewChanged;

_stack = new StackPanel { Orientation = Orientation.Vertical };
_scrollViewer.Content = _stack;

return _scrollViewer;
}

protected override void ConnectHandler(ScrollViewer platformView)
{
_scrollViewer.ViewChanged += OnScrollViewerViewChanged;
base.ConnectHandler(platformView);
}

protected override void DisconnectHandler(ScrollViewer platformView)
{
_scrollViewer.ViewChanged -= OnScrollViewerViewChanged;
base.DisconnectHandler(platformView);
}

async Task RenderPages()
{
_stack.Children.Clear();
Expand Down

0 comments on commit 4941d66

Please sign in to comment.