Good morning,
I am wondering, if it is possible to expand the pre-defined zoom levels in the combobox for the PdfViewer. I searched the documentation, but was not able to find a guide in how to achieve it. There are instructions on how to set it programmatically. But that's not what I need.
Our customer has some PDFs which are really big. And to get a better overview they would like to zoom out more then the combobox offers. I already set the minimum zoomlevel to 10% and the maximum zoom level to 600%. But as soon as you reach 50% zoom level, the zoom out button gets disabled. You can further zoom to 10% via control + mouse wheel or by entering the number directly into the textfield, but it would be really great, if it is possible to expand the pre-defined zoom levels.
With regards
Hello Divya,
the provided solution looks good so far. The only issue i have now is the mousewheel event. Using ctrl + mousewheel does not change the value of the CustomComboBox. Is there a way to overwrite or replace the default event, so that it influences the custom combobox instead?
Or maybe even unsubscribe all event so that ctrl + mousewheel doesn't zoom anymore?
With regards
|
CustomZoomComboBox.Text = "100%";
CustomZoomComboBox.IsEditable = true; |
|
//Rise the zoom changed value
pdfViewer.ZoomChanged += PdfViewer_ZoomChanged;
private void PdfViewer_ZoomChanged(object sender, ZoomEventArgs args)
{
int zoomValue = pdfViewer.ZoomPercentage;
if (zoomValue < pdfViewer.MinimumZoomPercentage)
zoomValue = pdfViewer.MinimumZoomPercentage;
if (zoomValue > pdfViewer.MaximumZoomPercentage)
zoomValue = pdfViewer.MaximumZoomPercentage;
//Set the custom zoom combobox value based on current zoom percentage of PDF Viewer
CustomZoomComboBox.Text = zoomValue.ToString() + "%";
} |
|
//Rise ComboBox mouse down event
CustomZoomComboBox.KeyDown += CustomZoomComboBox_KeyDown;
private void CustomZoomComboBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
ComboBox zoomBox = sender as ComboBox;
if (e.Key == Key.Enter)
{
string zoomEntered = zoomBox.Text;
int magnificationValue;
if (zoomEntered.Contains("%"))
{
int index = zoomEntered.IndexOf('%');
zoomEntered = zoomEntered.Substring(0, index);
}
int.TryParse(zoomEntered, out magnificationValue);
if (magnificationValue < pdfViewer.MinimumZoomPercentage)
magnificationValue = pdfViewer.MinimumZoomPercentage;
if (magnificationValue > pdfViewer.MaximumZoomPercentage)
magnificationValue = pdfViewer.MaximumZoomPercentage;
pdfViewer.ZoomTo(magnificationValue);
CustomZoomComboBox.Text = magnificationValue.ToString() + "%";
}
} |
Hi Divya,
sorry for the delayed feedback, but I finally got to implement your solution and it looks solid.
I had to do a little bit of tweaking regarding the zoom in and zoom out buttons.
private void ZoomOutBtn_Click(object sender, RoutedEventArgs e)
{
int currentZoomLevel = GetCurrentZoomLevel();
int index = GetComboBoxItemIndex(string.Format("{0}%", currentZoomLevel));
if (index - 1 >= 0)
{
CustomZoomComboBox.SelectedIndex = index - 1;
}
else
{
for (int i = 0; i < CustomZoomComboBox.Items.Count; i++)
{
if (i + 1 < CustomZoomComboBox.Items.Count)
{
if (currentZoomLevel >= Convert.ToInt32(CustomZoomComboBox.Items[i]) && currentZoomLevel < Convert.ToInt32(CustomZoomComboBox.Items[i + 1]))
{
CustomZoomComboBox.SelectedIndex = i;
break;
}
}
}
}
ZoomBtnChanges();
}
The problem was, if you zoom via mouse wheel and then try to use the zoom buttons it would end up in the else-case which in turn throws an exception, because you can't convert "10%" to an int. I managed to avoid the exception by triming the % from the string:
string valueAtIndex = CustomZoomComboBox.Items[i].ToString().TrimEnd('%');
string valueAtNextIndex = CustomZoomComboBox.Items[i + 1].ToString().TrimEnd('%');
if (currentZoomLevel >= Convert.ToInt32(valueAtIndex) && currentZoomLevel < Convert.ToInt32(valueAtNextIndex))
Thank you very much for your help.
With kind tegards