|
using System;
using System.Collections.Generic;
using System.Windows;
using Microsoft.Win32;
namespace CoreMVVM.Services
{
/// <summary>
/// This class implements the IOpenFileService for WPF purposes.
/// </summary>
public class OpenFileService : IOpenFileService
{
#region Data
/// <summary>
/// Embedded OpenFileDialog to pass back correctly selected
/// values to ViewModel
/// </summary>
private OpenFileDialog ofd = new OpenFileDialog();
#endregion
#region IOpenFileService Members
/// <summary>
/// This method should show a window that allows a file to be selected
/// </summary>
/// <param name="owner">The owner window of the dialog</param>
/// <returns>A bool from the ShowDialog call</returns>
public bool? ShowDialog(Window owner)
{
//Set embedded OpenFileDialog.Filter
if (!String.IsNullOrEmpty(this.Filter))
ofd.Filter = this.Filter;
//Set embedded OpenFileDialog.InitialDirectory
if (!String.IsNullOrEmpty(this.InitialDirectory))
ofd.InitialDirectory = this.InitialDirectory;
//return results
return ofd.ShowDialog(owner);
}
/// <summary>
/// FileName : Simply use embedded OpenFileDialog.FileName
/// But DO NOT allow a Set as it will ONLY come from user
/// picking a file
/// </summary>
public string OpenedFileName
{
get { return ofd.FileName; }
set
{
//Do nothing
}
}
/// <summary>
/// Filter : Simply use embedded OpenFileDialog.Filter
/// </summary>
public string Filter
{
get { return ofd.Filter; }
set { ofd.Filter = value; }
}
/// <summary>
/// Filter : Simply use embedded OpenFileDialog.InitialDirectory
/// </summary>
public string InitialDirectory
{
get { return ofd.InitialDirectory; }
set { ofd.InitialDirectory = value; }
}
#endregion
}
}
|
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.
He is a Software Engineer at Rockwell Automation Asia Pacific Business Center, working on RSLogix 5000. Prior to joining Rockwell Automation, he had worked for Sybase for 8 years and was the original architect of the PowerBuilder Native Interface and the PowerBuilder .NET Compiler that can compile PowerBuilder applications to .NET Windows Forms or Web Forms applications. The programming languages he has used or is using intensively include C#, C++, C and 8086 assembly.
Wu XueSong's Blog