您好我正在使用WPF和Devexpress!我是c#世界的新手,對MVVM沒有經驗。我看過不同的視頻來學習MVVM。但所有這些都與MVVM的基礎知識有關(爲什麼它很高效等)我在WPF中編寫代碼。我的代碼中有三個按鈕:添加新數據,編輯數據和刷新網格。每個按鈕都有定義它功能的單擊事件。我想將這個簡單的基本WPF代碼轉換成MVVM框架。任何人都可以指導我轉換到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;
}
}
如果我的問題不明確您或您想了解更多信息請諮詢我。謝謝:)
如果您使用mvvm,您的XAML在哪裏? – Default
我沒有使用MVVM。我想把這個簡單的代碼放到MVVM中。請仔細閱讀我的查詢。謝謝@Default –
@Default'我想將這段代碼轉換成MVVM。任何人都可以引導我轉換到MVVM。「# – Viv