重写设置窗口
This commit is contained in:
@@ -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<CancelEventArgs>(OnClosingWindow);
|
||||
|
||||
OpenSettingWindowCommand = new ObjectPassingCommand(OnOpenSettingWindowCommand);
|
||||
//create view
|
||||
_viewList = new ObservableCollection<UserControl>();
|
||||
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
|
||||
/// <summary>
|
||||
///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<T>(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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user