You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
A NotImplementedException is thrown when binding two-way to a MVVM model, and resetting that model to null. This bug seems related to #1330, but has some specifics that could mean there is a secondary bug, or at least a good test case.
Call stack on this.DataContext = default;:
at Microsoft.Web.WebView2.Wpf.WebView2.SourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Replace the code in the MainWindow.xaml.cs with this:
public partial class MainWindow : Window
{
public MainWindow()
{
ViewModel m = new ViewModel()
{ Url = new Uri("https://google.com")
};
this.InitializeComponent();
this.DataContext = m;
}
/// <summary>
/// Raises the System.Windows.Window.Closed event.
/// </summary>
/// <param name="e">An System.EventArgs that contains the event data.</param>
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
//
// Reset data context and model to default.
//
this.DataContext = default;
}
}
public class ViewModel : DependencyObject
{
/// <summary>
/// Gets the Url dependency property.
/// </summary>
public static readonly DependencyProperty UrlProperty = DependencyProperty.Register(nameof(Url), typeof(Uri), typeof(ViewModel));
/// <summary>
/// Gets or sets the URL.
/// </summary>
public Uri Url
{
get { return (Uri)this.GetValue(UrlProperty); }
set { this.SetValue(UrlProperty, value); }
}
}
Open the app, close the app after the Google home page has loaded. On closing, an exception is raised.
Expected no exceptions to be raised and the unbound value to be allowed, or rewritten to something like about:blank.
The text was updated successfully, but these errors were encountered:
PatrickHofman
changed the title
Resetting Window.DataContext with MVVM model raised NotImplementedException
Resetting Window.DataContext with two-way bound MVVM model raises NotImplementedException
Jun 18, 2021
Description
A
NotImplementedException
is thrown when binding two-way to a MVVM model, and resetting that model tonull
. This bug seems related to #1330, but has some specifics that could mean there is a secondary bug, or at least a good test case.Call stack on
this.DataContext = default;
:Version
SDK: 1.0.864.35
Runtime: Unknown
Framework: WPF
OS: Win10 21H1 19043.1055
Repro Steps
MainWindow.xaml
:MainWindow.xaml.cs
with this:Open the app, close the app after the Google home page has loaded. On closing, an exception is raised.
Expected no exceptions to be raised and the unbound value to be allowed, or rewritten to something like
about:blank
.The text was updated successfully, but these errors were encountered: