From 296d450496364178fb8e5992aaba7408e5e91b13 Mon Sep 17 00:00:00 2001 From: yangwx Date: Thu, 13 Mar 2025 01:06:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E8=AE=BE=E7=BD=AE=E7=AA=97?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Data/20250313/20250313_0.txt | 1 + MainWindow.xaml | 130 ++++++++++---------- MainWindow.xaml.cs | 5 + ValueConverter/BoolToVisibilityConverter.cs | 20 +++ ViewModels/MainViewModel.cs | 48 ++++++-- Views/ChatMdView.xaml | 14 ++- Views/SettingView.xaml | 30 ++--- Views/SettingView.xaml.cs | 7 +- 8 files changed, 160 insertions(+), 95 deletions(-) create mode 100644 Data/20250313/20250313_0.txt create mode 100644 ValueConverter/BoolToVisibilityConverter.cs diff --git a/Data/20250313/20250313_0.txt b/Data/20250313/20250313_0.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Data/20250313/20250313_0.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/MainWindow.xaml b/MainWindow.xaml index d40905d..c11dce4 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -6,6 +6,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:behaviors="clr-namespace:YwxApp.AiChat.Commands" xmlns:ViewModels="clr-namespace:YwxApp.AiChat.ViewModels" + xmlns:ValueConverter="clr-namespace:YwxApp.AiChat.ValueConverter" mc:Ignorable="d" WindowStartupLocation="CenterScreen" Title="ChatAI" Height="600" Width="800" MinHeight="600" MinWidth="800"> @@ -14,75 +15,74 @@ + - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index f6e2224..e9f19ad 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using System.Windows; +using YwxApp.AiChat.ViewModels; namespace YwxApp.AiChat; @@ -7,11 +8,15 @@ namespace YwxApp.AiChat; /// public partial class MainWindow : Window { + MainViewModel viewModel; public MainWindow() { InitializeComponent(); + this.viewModel = this.DataContext as MainViewModel; //OllamaService ollamaService = new(); //ollamaService.Configure("http://192.168.1.3:11434", "deepseek-r1:1.5b"); //this.DataContext = new ChatViewModel(new OllamaService()); } + + } \ No newline at end of file diff --git a/ValueConverter/BoolToVisibilityConverter.cs b/ValueConverter/BoolToVisibilityConverter.cs new file mode 100644 index 0000000..1cd5c3e --- /dev/null +++ b/ValueConverter/BoolToVisibilityConverter.cs @@ -0,0 +1,20 @@ +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace YwxApp.AiChat.ValueConverter +{ + public class BoolToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return (bool)value ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return (Visibility)value == Visibility.Visible; + } + } + +} diff --git a/ViewModels/MainViewModel.cs b/ViewModels/MainViewModel.cs index c0e8b5a..765ef4e 100644 --- a/ViewModels/MainViewModel.cs +++ b/ViewModels/MainViewModel.cs @@ -7,8 +7,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Threading; using YwxApp.AiChat.Commands; -using YwxApp.AiChat.Views; - +using YwxApp.AiChat.Views; namespace YwxApp.AiChat.ViewModels { public class MainViewModel : INotifyPropertyChanged @@ -24,6 +23,18 @@ namespace YwxApp.AiChat.ViewModels #endregion #region Property + + private Visibility _isMenuOpen = Visibility.Visible; + public Visibility IsMenuOpen + { + get => _isMenuOpen; + set + { + _isMenuOpen = value; + OnPropertyChanged(); + } + } + public object CurrentView { get => _currentView; @@ -69,6 +80,7 @@ namespace YwxApp.AiChat.ViewModels #region Command public ICommand SwitchToViewCommand { get; } public ICommand ClosingWindowCommand { get; } + public ICommand OpenSettingWindowCommand { get; } #endregion @@ -83,10 +95,10 @@ namespace YwxApp.AiChat.ViewModels //bind command method SwitchToViewCommand = new ObjectPassingCommand(OnSwitchToView); ClosingWindowCommand = new EventsCommand(OnClosingWindow); - + OpenSettingWindowCommand = new ObjectPassingCommand(OnOpenSettingWindowCommand); //create view _viewList = new ObservableCollection(); - ViewList.Add(new SettingView(_ollamaObject)); + ViewList.Add(new ChatMdView(_ollamaObject)); //Set the default display of subview 1. @@ -95,6 +107,8 @@ namespace YwxApp.AiChat.ViewModels CurrentView = ViewList[0]; } + + #region The window close event /// ///trigger close event @@ -137,9 +151,17 @@ namespace YwxApp.AiChat.ViewModels #region Command method #region View switch + + private void OnOpenSettingWindowCommand(object obj) + { + var setting = new SettingView(_ollamaObject); + setting.ShowDialog(); + } //set the view public void OnSwitchToView(object operationItem) { + + var viewObj = ViewList.FirstOrDefault(viewObj => viewObj.GetType().Name.Equals(operationItem)); if (viewObj == null) { @@ -148,10 +170,7 @@ namespace YwxApp.AiChat.ViewModels { case "ChatMdView": newViewObj = new ChatMdView(_ollamaObject); - break; - case "SettingView": - newViewObj = new SettingView(_ollamaObject); - break; + break; default: break; } @@ -173,6 +192,19 @@ namespace YwxApp.AiChat.ViewModels { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + protected bool SetProperty(ref T field, T newValue, [CallerMemberName] string propertyName = null) + { + if (!Equals(field, newValue)) + { + field = newValue; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + return true; + } + + return false; + } + #endregion } diff --git a/Views/ChatMdView.xaml b/Views/ChatMdView.xaml index 9fd4702..1e18c47 100644 --- a/Views/ChatMdView.xaml +++ b/Views/ChatMdView.xaml @@ -18,8 +18,7 @@ - - + @@ -37,6 +36,10 @@ + + + + +