I am not sure if you may have seen the following. These two are equivalent:
datePicker.Loaded += (s, a) =>
{
var textBox1 = (TextBox)datePicker.Template.FindName("PART_TextBox", datePicker);
textBox1.Background = datePicker1.Background;
};
datePicker.Loaded += delegate
{
var textBox1 = (TextBox)datePicker.Template.FindName("PART_TextBox", datePicker);
textBox1.Background = datePicker1.Background;
};
Both these use the RoutedEventHandler delegate:
public delegate void RoutedEventHandler(object sender, RoutedEventArgs e);
You could also do the following
void datePicker_Loaded(object sender, RoutedEventArgs e)
{
var textBox1 = (TextBox)datePicker.Template.FindName("PART_TextBox", datePicker);
textBox1.Background = datePicker1.Background;
}
then you would assign the handler as:
DatePicker.Loaded += new RoutedEventHandler(datePicker1_Loaded);
or
DatePicker.Loaded += datePicker1_Loaded;