Witam.
Mój projekt opiera się na Toturialu WPF Application using the MVVM pattern, którego kod jest dostępny na tej stronie :
http://download.microsoft.com/download/5/C/8/5C8656D2-7926-4F2F-A188-AEE24ACBDC4B/HDI-WPF-source-MVVMIntro_cs.zip
Potrzebuję pozbyć się przycisku "Check for Invasion"
Jego zbindowana komenda "InvasionCommand" ma być wykonywana (np co 100ms) w osobnym wątku.
Aby było to możliwe, zamieniłem wszelkie potrzebne metody na static, wystarczy że podmienicie te 2 kody:
"App.xaml.cs"
using System.Windows;
using HDI_WPF_MVVMIntro_cs.ViewModel;
using System.Threading;
namespace HDI_WPF_MVVMIntro_cs
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
Thread _watek = new Thread(new ThreadStart(program_watku));
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
MainWindow window = new MainWindow();
var viewModel = new MainWindowViewModel();
window.DataContext = viewModel;
window.Show();
_watek.Start();
}
static void program_watku()
{
string[] param = new string[5];
EmployeeListViewModel.InvasionCommand.Execute(param);
}
}
}
"EmployeeListViewModel.cs"
using System;
using System.Collections.ObjectModel;
using HDI_WPF_MVVMIntro_cs.DataAccess;
using System.Windows.Input;
using System.Windows.Media;
namespace HDI_WPF_MVVMIntro_cs.ViewModel
{
class EmployeeListViewModel : ViewModelBase
{
readonly EmployeeRepository _employeeRepository;
static RelayCommand _invasionCommand;
public static ObservableCollection<Model.Employee> AllEmployees
{
get;
private set;
}
public EmployeeListViewModel(EmployeeRepository employeeRepository)
{
if (employeeRepository == null)
{
throw new ArgumentNullException("employeeRepository");
}
_employeeRepository = employeeRepository;
AllEmployees = new ObservableCollection<Model.Employee>(_employeeRepository.GetEmployees());
}
protected override void OnDispose()
{
AllEmployees.Clear();
}
private Brush _bgBrush;
public Brush BackgroundBrush
{
get
{
return _bgBrush;
}
set
{
_bgBrush = value;
OnPropertyChanged("BackgroundBrush");
}
}
public static ICommand InvasionCommand
{
get
{
if (_invasionCommand == null)
{
_invasionCommand = new RelayCommand(param => InvasionCommandExecute(), param => InvasionCommandCanExecute);
}
return _invasionCommand;
}
}
static void InvasionCommandExecute()
{
AllEmployees.Add(Model.Employee.CreateEmployee("Imię","azwisko"));
}
static bool InvasionCommandCanExecute
{
get
{
if (AllEmployees.Count == 0)
{
return false;
}
return true;
}
}
}
}
Proszę o pomoc, nigdzie nie mogę znaleźć na to rozwiązania.