I'm a little surprised that when learning WPF / XAML / Silverlight, almost all the XAML / C # examples I came across have “Click” events in XAML and very few in the Window or Page constructor.
With all the emphasis these days on "non-intrusive Javascript," I would think that more developers would actually structure their XAML / code like this:
XAML:
<Grid> <Button x:Name="btnEdit"/> </Grid>
Code behind:
public Window1() { InitializeComponent(); btnEdit.Content = "Edit"; btnEdit.Click += new RoutedEventHandler(btnEdit_Click); } private void btnEdit_Click(object sender, RoutedEventArgs e) { btnEdit.Content = "This button was clicked."; }
Any thoughts on why this would be good or bad practice?
source share