How to pass the name of a wpf window as a parameter

0

I use% custom% to show userControl and when I double-click on a line, I call a register window, which is expecting to send Data Grid of the selected line as a parameter, I wanted to simplify passing this method of all screens from ID to Data Grid customized as virtual method, so in double click I would call only the method, but I can not pass the window name as a parameter.

Failed example of the userControl virtual method (in theory this would be)

public virtual void AbrirJanelaCadastro(Window window, DataGrid grid) 
{
    DataRow dataRow = (grid.SelectedItem as DataRowView).Row;
    window(dataRow.Field<Int32>("ID")).ShowDialog();
}

Example of calling the method to open the window in double click

private void grid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed)
        AbrirJanelaCadastro(Cliente, Grid);
    
asked by anonymous 26.03.2017 / 20:57

1 answer

1

At the time of calling the Window, instantiate the window object to open and set the Title property

 Window1 w = new Window1();
 w.Title = "Seu Título";
 w.Show();

where is "Your Title"; you should put the value of your DataRow

In your code, it could look like this:

 DataRow dataRow = (grid.SelectedItem as DataRowView).Row;
 window.Title = dataRow.Field<Int32>("ID").ToString();
 window.ShowDialog();
    
02.05.2017 / 14:06