Problem
I have a main window with multiple Menu Items on the left hand side acting as a navigation bar. Menu items open different user control on the main window. Here is an example of one user control.
- A data-grid view where a user is able to select a single record.
- That selected item can be deleted from the database by click of a button. (Not a problem, because I can hook this to a ViewModel where the command is held to delete the record.
- That selected item can be updated on click of a button. New screen shows up with the textboxes already filled with data we selected. (My main concern).
Current Code
View: FSQMView.xaml
Here is an example of a view, as you can see I have a DataGrid, it loads records from FSQMRecords
with a single column called DocumentReference
.
<DataGrid x:Name="FSQMGrid"
ItemsSource="{Binding FSQMRecords}"
IsReadOnly="True"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding DocumentReference}" Header="Document Reference"/>
</DataGrid.Columns>
</DataGrid>
View .cs: FSQMView.xaml.cs
This might be a bad practise because to me it seems like I am going against the MVVM pattern.
Here I am passing the SelectedItem
from the DataGrid to the new window.
private void UpdateButton_Click(object sender, RoutedEventArgs e)
{
FSQMUpdate window = new FSQMUpdate()
{
DataContext = FSQMGrid.SelectedItem
};
window.ShowDialog();
}
View: FSQMUpdate.xaml
In the new window, I am receiving the data and display it in the textbox. Also, I would have another 2 buttons where I can update the record and click cancel to exit the screen.
<TextBox Text="{Binding DocumentReference, Mode=OneTime}"/>
<Button Command="{Binding UpdateCommand}"
Click="Update"/>
<Button Command="{Binding CancelCommand}"
Click="Cancel Edit"/>
Question
Would this be the correct way of loading a dialog inside a user control?