Basic setup completed

This commit is contained in:
Tracy Pearson
2022-08-11 22:50:48 -04:00
parent 3394607abf
commit 1286066abc
6 changed files with 113 additions and 2 deletions

View File

@@ -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>

View File

@@ -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();
}
}
}

View 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);
}
}
}

View 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
{
}
}

View 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;
}
}
}

View 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
{
}
}