Okay, I have a bit of a weird bug...
This works fine:
private void radioButtonNormalPoint_Checked(object sender, RoutedEventArgs e)
{
//comboBoxNormal
This is often caused by an attempt to process a null object. An example, trying to empty a Bindable list that is null will trigger the exception:
public class MyViewModel {
[BindableProperty]
public virtual IList<Products> ProductsList{ get; set; }
public MyViewModel ()
{
ProductsList.Clear(); // here is the problem
}
}
This could easily be fixed by checking for null:
if (ProductsList!= null) ProductsList.Clear();
To diagnose this issue, place the line of code causing the TargetInvocationException inside the try block.
To troubleshoot this type of error, get the inner exception. It could be due to a number of different issues.
try
{
// code causing TargetInvocationException
}
catch (Exception e)
{
if (e.InnerException != null)
{
string err = e.InnerException.Message;
}
}
I think you will have fewer problems if you declared a Property that implements INotifyPropertyChanged, then databind IsChecked
, SelectedIndex
(using IValueConverter) and Fill
(using IValueConverter) to it instead of using the Checked Event to toggle SelectedIndex
and Fill
.
If the radiobutton-checked event occurs before the content of the window is loaded fully, i.e. the ellipse is loaded fully, such an exception will be thrown. So check if the UI of the window is loaded (probably by Window_ContentRendered event, etc.).
The event is probably raised before the elements are fully loaded or the references are still unset, hence the exceptions. Try only setting properties if the reference is not null
and IsLoaded
is true
.