Firstly, this is a simplified version using the wizard using MVVM. The problem is simply easier to reproduce, as described below
After a significant reduction, I resolved an infinite exception in my code due to WPF ContentControl. However, I have yet to figure out how to handle this except try-catch, completing all of my possible instance code. Here is an example code that reproduces this ... any help on how to save this endless exception would be greatly appreciated.
additional information
To summarize, the problem is that if the content control modifies its contents and the loaded thing throws an exception, then it will throw and then retry loading, causing a repeated reset.
MainWindow.xaml
<Window x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Name ="Main">
<Grid>
<ContentControl Name="bar" Content="{Binding ElementName=Main, Path=foo}"/>
<Button Click="ButtonBase_OnClick" Margin="20" Width="50"/>
</Grid>
</Window>
MainWindow.xaml.cs
public partial class MainWindow : Window, INotifyPropertyChanged
{
private UserControl _foo;
public UserControl foo
{
get { return _foo; }
set { _foo = value; OnPropertyChanged("foo"); }
}
public MainWindow()
{
InitializeComponent();
foo = new UserControl1();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
foo = new UserControl2();
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
UserControl1
UserControl2.xaml.cs
public UserControl2()
{
InitializeComponent();
throw new Exception();
}