Skip to content

Commit 0fe3cbd

Browse files
947956
1 parent 417834e commit 0fe3cbd

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

Toolbar/CustomToolbar/ViewModel/ViewModel.cs

+46-40
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public String FilePath
8484
}
8585
}
8686
/// <summary>
87-
/// Gets or sets the selected item.
87+
/// Gets or sets the Zoom combo box selected item.
8888
/// </summary>
8989
public string SelectedItem
9090
{
@@ -186,7 +186,7 @@ public void Window_SizeChanged(object sender, SizeChangedEventArgs e)
186186
}
187187
}
188188
/// <summary>
189-
/// Opens a file dialog to select a PDF file, loads the selected document into the PDF viewer,
189+
/// Handles the open file dialog to load a PDF document into the viewer.
190190
/// </summary>
191191
/// <param name="sender">The button that triggered the event.</param>
192192
/// <param name="e">Event data for the RoutedEventArgs.</param>
@@ -255,29 +255,32 @@ private void OnItemSelect(string selectedItem)
255255
if (selectedItem != null)
256256
{
257257
string[] zoomPercentage = selectedItem.ToString().Split(':');
258-
259-
if (zoomPercentage[1] != "" && m_customToolbarWindow.ZoomComboBox.IsDropDownOpen)
260-
{
261-
m_customToolbarWindow.pdfviewer.ZoomTo(int.Parse(zoomPercentage[1]));
262-
m_customToolbarWindow.ZoomComboBox.Text = m_customToolbarWindow.pdfviewer.ZoomPercentage.ToString();
263-
m_customToolbarWindow.FitWidth.IsEnabled = true;
264-
m_customToolbarWindow.FitPage.IsEnabled = true;
265-
m_customToolbarWindow.ZoomOut.IsEnabled = true;
266-
m_customToolbarWindow.ZoomIn.IsEnabled = true;
267-
}
268-
if (zoomPercentage[1].Equals(" 50"))
269-
{
270-
m_customToolbarWindow.ZoomOut.IsEnabled = false;
271-
m_customToolbarWindow.ZoomIn.IsEnabled = true;
272-
}
273-
if (zoomPercentage[1].Equals(" 400"))
258+
if (zoomPercentage.Length > 1)
274259
{
275-
m_customToolbarWindow.ZoomOut.IsEnabled = true;
276-
m_customToolbarWindow.ZoomIn.IsEnabled = false;
260+
string zoomValue = zoomPercentage[1].Trim();
261+
if (!string.IsNullOrEmpty(zoomValue) && m_customToolbarWindow.ZoomComboBox.IsDropDownOpen)
262+
{
263+
m_customToolbarWindow.pdfviewer.ZoomTo(int.Parse(zoomValue));
264+
m_customToolbarWindow.ZoomComboBox.Text = m_customToolbarWindow.pdfviewer.ZoomPercentage.ToString();
265+
m_customToolbarWindow.FitWidth.IsEnabled = true;
266+
m_customToolbarWindow.FitPage.IsEnabled = true;
267+
m_customToolbarWindow.ZoomOut.IsEnabled = true;
268+
m_customToolbarWindow.ZoomIn.IsEnabled = true;
269+
}
270+
if (zoomValue.Equals(zoomLevels[0].ToString()))
271+
{
272+
m_customToolbarWindow.ZoomOut.IsEnabled = false;
273+
m_customToolbarWindow.ZoomIn.IsEnabled = true;
274+
}
275+
if (zoomValue.Equals(zoomLevels[6].ToString()))
276+
{
277+
m_customToolbarWindow.ZoomOut.IsEnabled = true;
278+
m_customToolbarWindow.ZoomIn.IsEnabled = false;
279+
}
277280
}
278-
279281
}
280282
}
283+
281284
/// <summary>
282285
/// Sets the PDF viewer zoom mode to Fit Page and updates the toolbar controls accordingly.
283286
/// </summary>
@@ -326,7 +329,7 @@ private void ZoomIn_Click(object sender, RoutedEventArgs e)
326329
if (m_customToolbarWindow.pdfviewer.LoadedDocument != null)
327330
{
328331
int currentZoom = m_customToolbarWindow.pdfviewer.ZoomPercentage;
329-
int nextZoom =0 ;
332+
int nextZoom = -1;
330333
int currentIndex = Array.IndexOf(zoomLevels, currentZoom);
331334
if (currentIndex != -1)
332335
{
@@ -346,7 +349,7 @@ private void ZoomIn_Click(object sender, RoutedEventArgs e)
346349
}
347350
}
348351
}
349-
if(nextZoom !=0)
352+
if(nextZoom != -1)
350353
{
351354
m_customToolbarWindow.pdfviewer.ZoomTo(nextZoom);
352355
m_customToolbarWindow.ZoomComboBox.Text = nextZoom.ToString();
@@ -368,7 +371,7 @@ private void ZoomOut_Click(object sender, RoutedEventArgs e)
368371
if (m_customToolbarWindow.pdfviewer.LoadedDocument != null)
369372
{
370373
int currentZoom = m_customToolbarWindow.pdfviewer.ZoomPercentage;
371-
int nextZoom = 0;
374+
int nextZoom = -1;
372375
int currentIndex = Array.IndexOf(zoomLevels, currentZoom);
373376
if (currentIndex != -1)
374377
{
@@ -389,7 +392,7 @@ private void ZoomOut_Click(object sender, RoutedEventArgs e)
389392
}
390393

391394
}
392-
if (nextZoom != 0)
395+
if (nextZoom != -1)
393396
{
394397
m_customToolbarWindow.pdfviewer.ZoomTo(nextZoom);
395398
m_customToolbarWindow.ZoomComboBox.Text = nextZoom.ToString();
@@ -596,23 +599,26 @@ private void ZoomComboBox_KeyDown(object sender, KeyEventArgs e)
596599
string zoomEntered = zoomBox.Text;
597600
int magnificationValue;
598601
int.TryParse(zoomEntered, out magnificationValue);
599-
int minimumZoomPercentage = m_customToolbarWindow.pdfviewer.MinimumZoomPercentage;
600-
int maximumZoomPercentage = m_customToolbarWindow.pdfviewer.MaximumZoomPercentage;
602+
if (magnificationValue != 0)
603+
{
604+
int minimumZoomPercentage = m_customToolbarWindow.pdfviewer.MinimumZoomPercentage;
605+
int maximumZoomPercentage = m_customToolbarWindow.pdfviewer.MaximumZoomPercentage;
601606

602-
if (magnificationValue < minimumZoomPercentage)
603-
magnificationValue = minimumZoomPercentage;
604-
if (magnificationValue > maximumZoomPercentage)
605-
magnificationValue = maximumZoomPercentage;
606-
if (magnificationValue > minimumZoomPercentage && !m_customToolbarWindow.ZoomOut.IsEnabled)
607-
m_customToolbarWindow.ZoomOut.IsEnabled = true;
608-
if (magnificationValue < maximumZoomPercentage && !m_customToolbarWindow.ZoomIn.IsEnabled)
609-
m_customToolbarWindow.ZoomIn.IsEnabled = true;
610-
m_customToolbarWindow.FitWidth.IsEnabled = true;
611-
m_customToolbarWindow.FitPage.IsEnabled = true;
607+
if (magnificationValue < minimumZoomPercentage)
608+
magnificationValue = minimumZoomPercentage;
609+
if (magnificationValue > maximumZoomPercentage)
610+
magnificationValue = maximumZoomPercentage;
611+
if (magnificationValue > minimumZoomPercentage && !m_customToolbarWindow.ZoomOut.IsEnabled)
612+
m_customToolbarWindow.ZoomOut.IsEnabled = true;
613+
if (magnificationValue < maximumZoomPercentage && !m_customToolbarWindow.ZoomIn.IsEnabled)
614+
m_customToolbarWindow.ZoomIn.IsEnabled = true;
615+
m_customToolbarWindow.FitWidth.IsEnabled = true;
616+
m_customToolbarWindow.FitPage.IsEnabled = true;
612617

613-
m_customToolbarWindow.pdfviewer.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.Default;
614-
m_customToolbarWindow.pdfviewer.ZoomTo(magnificationValue);
615-
m_customToolbarWindow.ZoomComboBox.Text = magnificationValue.ToString();
618+
m_customToolbarWindow.pdfviewer.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.Default;
619+
m_customToolbarWindow.pdfviewer.ZoomTo(magnificationValue);
620+
m_customToolbarWindow.ZoomComboBox.Text = magnificationValue.ToString();
621+
}
616622
}
617623
}
618624
/// <summary>

0 commit comments

Comments
 (0)