using Microsoft.Win32;
|
using System.Windows;
|
using System.Windows.Controls;
|
|
namespace OpenTapEditor.UI
|
{
|
/// <summary>
|
/// FileSelector.xaml 的交互逻辑
|
/// </summary>
|
public partial class FileSelector : UserControl
|
{
|
public static readonly DependencyProperty FilePathProperty = DependencyProperty.Register(
|
"FilePath",
|
typeof(string),
|
typeof(FileSelector),
|
new FrameworkPropertyMetadata());
|
|
public static readonly DependencyProperty ModeProperty = DependencyProperty.Register(
|
"Mode",
|
typeof(int),
|
typeof(FileSelector),
|
new FrameworkPropertyMetadata(0));
|
|
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register(
|
"Filter",
|
typeof(string),
|
typeof(FileSelector),
|
new FrameworkPropertyMetadata(null));
|
|
public static readonly DependencyProperty ExtProperty = DependencyProperty.Register(
|
"Ext",
|
typeof(string),
|
typeof(FileSelector),
|
new FrameworkPropertyMetadata(null));
|
|
public string FilePath
|
{
|
get => (string)GetValue(FilePathProperty);
|
set
|
{
|
SetValue(FilePathProperty, value);
|
}
|
}
|
|
public int Mode
|
{
|
get => (int)GetValue(ModeProperty);
|
set
|
{
|
SetValue(ModeProperty, value);
|
}
|
}
|
|
public string Filter
|
{
|
get => (string)GetValue(FilterProperty);
|
set
|
{
|
SetValue(FilterProperty, value);
|
}
|
}
|
|
public string Ext
|
{
|
get => (string)GetValue(ExtProperty);
|
set
|
{
|
SetValue(ExtProperty, value);
|
}
|
}
|
|
public FileSelector()
|
{
|
DataContext = this;
|
InitializeComponent();
|
}
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
{
|
OpenFileDialog ofd = new OpenFileDialog
|
{
|
Filter = this.Filter,
|
DefaultExt = this.Ext,
|
Multiselect = false
|
};
|
if (ofd.ShowDialog() == true)
|
{
|
if (Mode == 1)
|
{
|
FilePath = "\"" + ofd.FileName.Replace("\\", "\\\\") + "\"";
|
}
|
else
|
{
|
FilePath = ofd.FileName;
|
}
|
}
|
}
|
}
|
}
|