Basic setup completed
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<Application x:Class="WpfViewModelFirst.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:WpfViewModelFirst"
|
||||
StartupUri="MainWindow.xaml">
|
||||
xmlns:local="clr-namespace:WpfViewModelFirst">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
|
||||
@@ -13,5 +13,11 @@ namespace WpfViewModelFirst
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
MainWindow mainWindow = new() { DataContext = new MainWindowViewModel() };
|
||||
mainWindow.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
49
WpfViewModelFirst/CustomCommand.cs
Normal file
49
WpfViewModelFirst/CustomCommand.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace WpfViewModelFirst
|
||||
{
|
||||
public class CustomCommand : ICommand
|
||||
{
|
||||
private readonly Action<object?> _execute;
|
||||
private readonly Predicate<object?>? _canExecute;
|
||||
|
||||
public CustomCommand(Action<object?> execute, Predicate<object?> canExecute)
|
||||
{
|
||||
_execute = execute;
|
||||
_canExecute = canExecute;
|
||||
}
|
||||
|
||||
public CustomCommand(Action<object?> execute)
|
||||
{
|
||||
_execute = execute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object? parameter)
|
||||
{
|
||||
return _canExecute == null || _canExecute(parameter);
|
||||
}
|
||||
|
||||
public event EventHandler? CanExecuteChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
CommandManager.RequerySuggested += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
CommandManager.RequerySuggested -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(object? parameter)
|
||||
{
|
||||
_execute(parameter);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
13
WpfViewModelFirst/MainWindowViewModel.cs
Normal file
13
WpfViewModelFirst/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WpfViewModelFirst
|
||||
{
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
31
WpfViewModelFirst/ObservableObject.cs
Normal file
31
WpfViewModelFirst/ObservableObject.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WpfViewModelFirst
|
||||
{
|
||||
public class ObservableObject
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected virtual bool Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = "")
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(storage, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
storage = value;
|
||||
this.RaisePropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
13
WpfViewModelFirst/ViewModelBase.cs
Normal file
13
WpfViewModelFirst/ViewModelBase.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WpfViewModelFirst
|
||||
{
|
||||
public class ViewModelBase : ObservableObject
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user