I am a doing a small WPF MVVM program that:
- Has a MainWindow with Label (saying "Hello") and a button to open another window (I did the open window part in code behind).
- This opens another window with 2 radio buttons (Red and Blue) and a cancel button (I did close function in code behind).
- If I press the Red radio button, the Label on MainWindow should turn Red, similarly with pressing the Blue radio button.
Can somebody help me with this? I am sort of new to WPF and completely new to MVVM methodology. I am posting my ViewModel code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using PocMVVM.Views;
namespace PocMVVM.ViewModel
{
public class ColorChangeViewModel : ICommand
{
//ColorChoiceView colorSelect = new ColorChoiceView();
//MainWindow mw = new MainWindow();
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
//throw new NotImplementedException();
}
public void Execute(object parameter)
{
//throw new NotImplementedException();
ColorChoiceView colorSelect = new ColorChoiceView();
MainWindow mw = new MainWindow();
if((bool)parameter==colorSelect.RedButton.IsChecked.Equals(true))
{
mw.label.Foreground = Brushes.Red;
mw.UpdateLayout();
mw.ShowDialog();
}
else if((bool)parameter == colorSelect.BlueButton.IsChecked.Equals(true))
{
mw.label.Foreground = Brushes.Blue;
mw.UpdateLayout();
mw.ShowDialog();
}
}
}
}
Can somebody help me with this?
Thank You Very Much!!
P.S. I know people might ask about the need for two windows, but it has to be this way. I was told it had to be like this, so no other way.