Hi i am using WPF and Devexpress! I am new to c# world and have no experience in MVVM. I have watched different videos to learn MVVM. But all are related to basics of MVVM (Why it is efficient, etc) I wrote code in WPF. There are three buttons in my code : Add new data, Edit Data and Refresh Grid. Each button has it's click event defining it's functionality. I want to convert this simple basic WPF code into MVVM framework. Can anyone guide me for it's conversion to MVVM. Edition
void EditRow(int focRowHand, Entities a)
{
Name nametext = grid.GetRow(focRowHand) as Name;
try
{
if (nametext.Name1 != string.Empty)
{
update_id = nametext.ID;
txtName2.Text = update_text = nametext.Name;
if (Panel3.Visibility == System.Windows.Visibility.Visible)
{
Panel1.Visibility = System.Windows.Visibility.Visible;
Panel3.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
Panel1.Visibility = System.Windows.Visibility.Collapsed;
Panel3.Visibility = System.Windows.Visibility.Visible;
}
}
}
catch (Exception err)
{
DXMessageBox.Show(err.StackTrace);
}
}
private void Button1_Copy_Click(object sender, RoutedEventArgs e)
{
if (view.FocusedRowHandle == 0)
{
DXMessageBox.Show("Please Select any Item From Grid List");
}
else
{
try
{
int FocRowHand = view.FocusedRowHandle;
Entities a = new Entities();
if (grid.IsGroupRowHandle(FocRowHand))
{
int childCount = grid.GetChildRowCount(FocRowHand);
for (int i = 0; i < childCount; i++)
{
int childHandle = grid.GetChildRowHandle(FocRowHand, i);
EditRow(childHandle, a);
}
}
else
{
EditRow(FocRowHand, a);
}
}
catch (Exception ee)
{
DXMessageBox.Show(ee.StackTrace);
}
}
}
Insertion
private void Insertion()
{
if (txtName.Text != string.Empty)
{
if (DXMessageBox.Show("Are You Sure, you Want to Insert?", "Insert Item-Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
try
{
Entities dbContext = new Entities();
Name name = new Name();
name.my_name = txtName.Text;
dbContext.Names.Add(name);
dbContext.SaveChanges();
txtName.Text = null;
Refresh();
}
catch (Exception err)
{
DXMessageBox.Show(err.StackTrace);
}
}
else
txtName.Text = null;
}
}
If my question is not clear to you or you want more information please ask me. Thank you :)