Skip to content

Commit db379d5

Browse files
Page Layout mode
1 parent c2ff88b commit db379d5

File tree

6 files changed

+202
-0
lines changed

6 files changed

+202
-0
lines changed

Custom Toolbar/CustomToolbar.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
<ItemGroup>
5656
<PackageReference Include="Syncfusion.Maui.PdfViewer" Version="*" />
57+
<PackageReference Include="Syncfusion.Maui.ListView" Version="*" />
5758
</ItemGroup>
5859

5960
<ItemGroup>
@@ -63,6 +64,9 @@
6364
</ItemGroup>
6465

6566
<ItemGroup>
67+
<MauiXaml Update="UI\PageLayoutModeDialog.xaml">
68+
<Generator>MSBuild:Compile</Generator>
69+
</MauiXaml>
6670
<MauiXaml Update="UI\MessageBox.xaml">
6771
<Generator>MSBuild:Compile</Generator>
6872
</MauiXaml>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="CustomToolbar.PageLayoutModeDialog"
5+
xmlns:sf="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView">
6+
7+
<Border
8+
x:Name="Colors"
9+
VerticalOptions="Start"
10+
HorizontalOptions="Start"
11+
WidthRequest="{OnPlatform MacCatalyst=205, iOS=150, Android=150, WinUI=205}"
12+
HeightRequest="84"
13+
Padding="0,0,0,0"
14+
StrokeShape="RoundRectangle 4">
15+
<sf:SfListView
16+
x:Name="listView" ItemTapped="SfListView_ItemTapped" ItemSize="40" >
17+
<sf:SfListView.ItemTemplate>
18+
<DataTemplate>
19+
<Border StrokeThickness="0">
20+
<Border.StrokeShape>
21+
<RoundRectangle CornerRadius="0" />
22+
</Border.StrokeShape>
23+
<Grid >
24+
<Grid.ColumnDefinitions>
25+
<ColumnDefinition Width="*"></ColumnDefinition>
26+
</Grid.ColumnDefinitions>
27+
<HorizontalStackLayout>
28+
<Label
29+
Padding="8,0,8,0"
30+
FontSize="18"
31+
32+
HeightRequest="18"
33+
FontFamily="Maui Material Assets"
34+
VerticalOptions="Center"
35+
Text="{Binding Icon}">
36+
</Label>
37+
<Label
38+
Padding="0,0,0,0"
39+
FontSize="{OnPlatform MacCatalyst=16, iOS=14, Android=14, WinUI=16}"
40+
FontFamily="Roboto"
41+
VerticalOptions="Center"
42+
Text="{Binding IconName}">
43+
</Label>
44+
</HorizontalStackLayout>
45+
</Grid>
46+
</Border>
47+
</DataTemplate>
48+
</sf:SfListView.ItemTemplate>
49+
</sf:SfListView>
50+
</Border>
51+
</ContentView>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Syncfusion.Maui.ListView;
2+
3+
namespace CustomToolbar;
4+
5+
/// <summary>
6+
/// PageLayoutModeDialog representing a dialog for selecting page layout mode.
7+
/// </summary>
8+
public partial class PageLayoutModeDialog : ContentView
9+
{
10+
/// <summary>
11+
/// Event raised when an item is tapped in the dialog.
12+
/// </summary>
13+
public event EventHandler<ItemTappedEventArgs> ItemTapped;
14+
15+
/// <summary>
16+
/// Initializes a new instance of the PageLayoutModeDialog class.
17+
/// </summary>
18+
public PageLayoutModeDialog()
19+
{
20+
Initialize();
21+
}
22+
internal void Initialize()
23+
{
24+
InitializeComponent();
25+
List<AnnotationButtonItem> items = new List<AnnotationButtonItem>()
26+
{
27+
new AnnotationButtonItem()
28+
{
29+
Icon = "\uE796",
30+
IconName = "Continuous page"
31+
},
32+
new AnnotationButtonItem()
33+
{
34+
Icon = "\uE797",
35+
IconName = "Page by page"
36+
37+
},
38+
};
39+
listView.ItemsSource = items;
40+
listView.SelectedItem = items[0];
41+
}
42+
43+
/// <summary>
44+
/// Handles the event when an item is tapped in the ListView.
45+
/// </summary>
46+
private void SfListView_ItemTapped(object sender, Syncfusion.Maui.ListView.ItemTappedEventArgs e)
47+
{
48+
if(sender is SfListView view)
49+
{
50+
51+
if (e.DataItem is AnnotationButtonItem buttonItem && BindingContext is PdfViewerViewModel viewModel)
52+
{
53+
if (buttonItem.IconName == "Continuous page")
54+
viewModel.PageLayoutMode = Syncfusion.Maui.PdfViewer.PageLayoutMode.Continuous;
55+
else
56+
viewModel.PageLayoutMode = Syncfusion.Maui.PdfViewer.PageLayoutMode.Single;
57+
}
58+
ItemTapped?.Invoke(this, new ItemTappedEventArgs(view));
59+
}
60+
}
61+
internal void DisappearHighlight()
62+
{
63+
// Clears the selection highlight in the ListView.
64+
listView.SelectedItem = null;
65+
}
66+
}
67+
68+
/// <summary>
69+
/// Represents an item in the dialog ListView.
70+
/// </summary>
71+
public class AnnotationButtonItem
72+
{
73+
public string Icon { get; set; }
74+
public string IconName { get; set; }
75+
}
76+
77+
/// <summary>
78+
/// Event arguments for the ItemTapped event.
79+
/// </summary>
80+
public class ItemTappedEventArgs : EventArgs
81+
{
82+
public View TappedItem;
83+
84+
public ItemTappedEventArgs(IView view)
85+
{
86+
TappedItem = view as View;
87+
}
88+
}

Custom Toolbar/View/MainPage.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<ColumnDefinition Width="{OnPlatform Default=Auto, Android=1*, iOS=1*}"/>
5454
<ColumnDefinition Width="{OnPlatform Default=*, Android=3*, iOS=3*}"/>
5555
<ColumnDefinition Width="{OnPlatform Default=*, Android=1*, iOS=1*}"/>
56+
<ColumnDefinition Width="{OnPlatform Default=40, Android=1*, iOS=1*}"/>
5657
</Grid.ColumnDefinitions>
5758
<HorizontalStackLayout Spacing="10" Grid.Column="0" Margin="8,0,0,0" HorizontalOptions="Start" >
5859
<Button Text="&#xe700;"
@@ -114,6 +115,14 @@
114115
Command="{Binding ZoomInCommand}" IsEnabled="{Binding CanZoomIn}"
115116
PropertyChanged="Button_PropertyChanged"/>
116117
</HorizontalStackLayout>
118+
<Grid Grid.Column="3" Margin="0,0,12,0" HorizontalOptions="{OnPlatform MacCatalyst=End, iOS=End, Android=End, WinUI=End}">
119+
<Button Text="&#xe795;"
120+
Margin="0,0,0,0"
121+
HorizontalOptions="End"
122+
FontFamily="Maui Material Assets"
123+
PropertyChanged="Button_PropertyChanged"
124+
Clicked="pageLayoutClicked"/>
125+
</Grid>
117126
</Grid>
118127
<Line Grid.Row="1" StrokeThickness="1" BackgroundColor="#33000000"/>
119128
<syncfusion:SfPdfViewer
@@ -136,6 +145,15 @@
136145
x:Name="MessageBox" Grid.Row="2"
137146
IsVisible="False"
138147
OkClicked="MessageBox_OKClicked"/>
148+
<local:PageLayoutModeDialog
149+
WidthRequest="{OnPlatform MacCatalyst=205, iOS=150, Android=150, WinUI=205}"
150+
BackgroundColor="#F7F2FB"
151+
HeightRequest="84"
152+
HorizontalOptions="End"
153+
VerticalOptions="Start"
154+
ItemTapped="PageLayoutModeChanged"
155+
x:Name="PageLayout" Grid.Row="2"
156+
IsVisible="false"/>
139157
</Grid>
140158
</ContentPage.Content>
141159
</ContentPage>

Custom Toolbar/View/MainPage.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Maui.Platform;
2+
using Syncfusion.Maui.PdfViewer;
23

34
namespace CustomToolbar;
45

@@ -182,4 +183,30 @@ private void MessageBox_OKClicked(object sender, EventArgs e)
182183
PdfViewer.DocumentSource = context.PdfDocumentStream;
183184
}
184185
}
186+
187+
/// <summary>
188+
/// Toggles the visibility of the page layout options when the page layout button is clicked.
189+
/// </summary>
190+
private void pageLayoutClicked(object sender, EventArgs e)
191+
{
192+
PageLayout.IsVisible = !PageLayout.IsVisible;
193+
}
194+
195+
/// <summary>
196+
/// Handles the change of page layout mode based on user selection.
197+
/// </summary>
198+
private void PageLayoutModeChanged(object sender, ItemTappedEventArgs e)
199+
{
200+
if (BindingContext is PdfViewerViewModel context)
201+
{
202+
// Set the page layout mode based on the selected mode.
203+
if (context.PageLayoutMode == Syncfusion.Maui.PdfViewer.PageLayoutMode.Continuous)
204+
PdfViewer.PageLayoutMode = PageLayoutMode.Continuous;
205+
else
206+
PdfViewer.PageLayoutMode = PageLayoutMode.Single;
207+
// Hide the page layout options after selection.
208+
PageLayout.IsVisible = false;
209+
}
210+
211+
}
185212
}

Custom Toolbar/ViewModel/PdfViewerViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.ComponentModel;
22
using System.Windows.Input;
3+
using Syncfusion.Maui.PdfViewer;
34

45
namespace CustomToolbar
56
{
@@ -19,6 +20,7 @@ public class PdfViewerViewModel : INotifyPropertyChanged
1920
private bool _showPasswordDialog = false;
2021
private Stream _documentStream;
2122
private int _pageCount;
23+
private PageLayoutMode _pageLayoutMode;
2224

2325
/// <summary>
2426
/// Occurs when a property is changed.
@@ -170,6 +172,18 @@ public int PageCount
170172
}
171173
}
172174

175+
/// <summary>
176+
/// Stores the pageLayout Mode of the PDF.
177+
/// </summary>
178+
public PageLayoutMode PageLayoutMode
179+
{
180+
get => _pageLayoutMode;
181+
set
182+
{
183+
_pageLayoutMode = value;
184+
OnPropertyChanged("PageLayoutMode");
185+
}
186+
}
173187
/// <summary>
174188
/// Gets the command to browse file in the disk.
175189
/// </summary>

0 commit comments

Comments
 (0)