Im migrating an application from Windows Forms to WPF, so I am trying to use the MVVM pattern, but it is getting a bit tricky to me.
In Windows forms I have a form which contains a progressBar which has defined some new methods that allow me to perform steps, set its value, etc. This code is placed in the progressBar's code behind as below:
public class MyProgressBar : ProgressBar
{
public MyProgressBar ()
{
InitializeComponent();
}
public void Method01()
{...}
public void Method02()
{...}
public void Method03()
{...}
}
The code of the Method01, Method02 and Method03 is used in the container form, so, here is my question: In WPF, since I use the MVVM pattern, Where do I have to place that code??
Until now I have this classes:
My model:
public class MyFormModel : DataTable
{
public OutputResultsDataTable()
: base()
{
Columns.Add(new DataColumn("Number"));
Columns.Add(new DataColumn("Message"));
Columns.Add(new DataColumn("Detail"));
}
}
My ViewModel:
public class MyNewWPFForm
{
/// <summary>
///
/// </summary>
public MyFormModel MyData{ get; set; }
/// <summary>
/// Constructor
/// </summary>
public MyNewWPFForm()
{
if (System.Windows.Application.Current.MainWindow != null)
{
MyData= new MyFormModel ();
}
}
}
In WPF I have already created my new progressBar control and its container form, even I have been reading about MVVM but I cant understand where do I have to put the code of the Method0X, because, according to what I have read, I would have to put that code in the viewModel, but, here is another problem: How could I have access to my progress bar from my view model since it is inside another form??
Hope someone can help me. Thanks in advance.