好吧,我有一个奇怪的错误……

这工作正常:

private void radioButtonNormalPoint_Checked(object sender, RoutedEventArgs e)
{
   //comboBoxNormalPoint.SelectedIndex = 0;
   //ellipsePoint.Fill = System.Windows.Media.Brushes.Black;
}

这会抛出System.Reflection.TargetInvocationException:

private void radioButtonNormalPoint_Checked(object sender, RoutedEventArgs e)
{
   comboBoxNormalPoint.SelectedIndex = 0;
   ellipsePoint.Fill = System.Windows.Media.Brushes.Black;
}

而且,它不允许我调试它;

答案

该事件可能在元素完全加载之前引发,或者引用仍未设置,因此会出现异常。nullIsLoadedtrue

来自: stackoverflow.com