嗨,我正在使用 WPF 和 Devexpress!我是 c# 世界的新手,在 MVVM 方面没有经验。我看过不同的视频来学习 MVVM。但所有这些都与 MVVM 的基础知识有关(为什么它高效等)我在 WPF 中编写了代码。我的代码中有三个按钮:添加新数据、编辑数据和刷新网格。每个按钮都有定义其功能的单击事件。我想将这个简单的基本 WPF 代码转换为 MVVM 框架。任何人都可以指导我将其转换为 MVVM。 版
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);
}
}
}
插入
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;
}
}
如果您不清楚我的问题或者您想了解更多信息,请询问我。谢谢 :)