-2

I have function in create.cs

    private void FillGrid()
    {
        ClearingEntities CE = new ClearingEntities();
        var Accountss = CE.Accounts;
        DataGrid1.ItemsSource = Accountss.ToList();
    }

I invoke this function from other .cs files just writing FillGrid(); without any arguments

but from xaml in button Click="FillGrid" gives error

click auto generated functions have

  private void Button_Click(object sender, RoutedEventArgs e)

I don't want insert those object sender, RoutedEventArgs e arguments

if I insert those to my function's arguments then other calling should be changed to

FillGrid([argument],[argument]);

note: it is not event handling function just fill data stuff

how to call FillGrid() from xaml? without changing create.cs

Baganaakh
  • 67
  • 1
  • 3
  • 17

1 Answers1

2

This is just the way Button Event's work. Read more about EventHandler here

Why don't you just use this:

<Button Click="FillGridClicked" />

//sender = button, RoutedEventArgs = arguments of that event
private void FillGridClicked(object sender, RoutedEventArgs e)
{
    FillGrid();
}

Every ClickEventHandler needs these arguments as it is a custom delegate defined that way. If you really want to emit this you need to extend the button and create a custom click handler for yourself. (see this for example)

Felix D.
  • 4,811
  • 8
  • 38
  • 72