|
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using Microsoft.Expression.Interactivity.Core;
namespace AcrobatViewerMvvm
{
public class MainWindowViewModel : INotifyPropertyChanged
{
private readonly string[] pdfChoices;
private string currentPdf;
private int currentPdfChoiceIndex;
public MainWindowViewModel()
{
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
{
return;
}
string currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
pdfChoices = new string[]
{
Path.Combine(currentFolder, "SamplePDF1.pdf"),
Path.Combine(currentFolder, "SamplePDF2.pdf"),
};
CurrentPdf = pdfChoices[currentPdfChoiceIndex];
SwapPdfsCommand = new ActionCommand(() =>
{
currentPdfChoiceIndex ^= 1;
CurrentPdf = pdfChoices[currentPdfChoiceIndex];
});
}
public event PropertyChangedEventHandler PropertyChanged;
public string CurrentPdf
{
get
{
return currentPdf;
}
set
{
if (currentPdf != value)
{
currentPdf = value;
OnPropertyChanged(new PropertyChangedEventArgs("CurrentPdf"));
}
}
}
public ICommand SwapPdfsCommand
{
get;
private set;
}
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.