WpfMdict / csharp /mdict /Views /LibraryView.xaml.cs
fasdfsa's picture
添加词典功能
e3ea2f2
Raw History Blame Contribute Delete
1.47 kB
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
using mdict.Services;
namespace mdict.Views
{
public partial class LibraryView : UserControl
{
public LibraryView()
{
InitializeComponent();
DictionariesList.ItemsSource = LibraryManager.Instance.LoadedDictionaries;
}
private void AddDictionary_Click(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
Filter = "MDict Files (*.mdx)|*.mdx|All Files (*.*)|*.*",
Multiselect = true
};
if (openFileDialog.ShowDialog() == true)
{
foreach (var filename in openFileDialog.FileNames)
{
try
{
LibraryManager.Instance.AddDictionary(filename);
}
catch (System.Exception ex)
{
MessageBox.Show($"Failed to load {filename}:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
private void RemoveDictionary_Click(object sender, RoutedEventArgs e)
{
if (sender is Button button && button.Tag is DictionaryItem item)
{
LibraryManager.Instance.RemoveDictionary(item);
}
}
}
}