DataContext change event was not triggered on .NET 8.0 because it brings its own DataContext property and related event, adapted the code to still fire my custom OnDataContextChange() notification
This commit is contained in:
parent
d057f70449
commit
7376852ae1
4 changed files with 56 additions and 25 deletions
|
@ -140,7 +140,7 @@ namespace Nuclex.Windows.Forms.Views {
|
|||
/// <summary>Discovers the container control used to host the child views</summary>
|
||||
/// <returns>The container control is which the child views will be hosted</returns>
|
||||
/// <remarks>
|
||||
/// This is supposed to be overriden by the user, simply returning the container
|
||||
/// This is supposed to be overridden by the user, simply returning the container
|
||||
/// control that should host the page views. If it isn't, however, we use some
|
||||
/// heuristics to figure out the most likely candidate: it should be a container,
|
||||
/// and it should cover most of the window's client area.
|
||||
|
|
|
@ -85,12 +85,23 @@ namespace Nuclex.Windows.Forms.Views {
|
|||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
/// <summary>Called when the control's data context has changed</summary>
|
||||
/// <param name="arguments">Not used</param>
|
||||
protected override void OnDataContextChanged(EventArgs arguments) {
|
||||
object oldDataContext = this.dataContext;
|
||||
this.dataContext = base.DataContext;
|
||||
|
||||
if(this.dataContext != oldDataContext) {
|
||||
OnDataContextChanged(this, oldDataContext, this.dataContext);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NET8_0_OR_GREATER
|
||||
// NOTE: Careful! On .NET 8.0, the Control class has its own DataContext,
|
||||
// but this one will be used to be able to report the previous one.
|
||||
/// <summary>Active data binding target, can be null</summary>
|
||||
private object dataContext;
|
||||
#endif
|
||||
/// <summary>Delegate for the OnViewModelPropertyChanged() method</summary>
|
||||
private PropertyChangedEventHandler onViewModelPropertyChangedDelegate;
|
||||
|
||||
|
|
|
@ -42,20 +42,6 @@ namespace Nuclex.Windows.Forms.Views {
|
|||
this.onViewModelPropertyChangedDelegate = OnViewModelPropertyChanged;
|
||||
}
|
||||
|
||||
#if !NET8_0_OR_GREATER
|
||||
/// <summary>Provides the data binding target for the view</summary>
|
||||
public object DataContext {
|
||||
get { return this.dataContext; }
|
||||
set {
|
||||
if(value != this.dataContext) {
|
||||
object oldDataContext = this.dataContext;
|
||||
this.dataContext = value;
|
||||
OnDataContextChanged(this, oldDataContext, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>Called when the window's data context is changed</summary>
|
||||
/// <param name="sender">Window whose data context was changed</param>
|
||||
/// <param name="oldDataContext">Data context that was previously used</param>
|
||||
|
@ -88,9 +74,34 @@ namespace Nuclex.Windows.Forms.Views {
|
|||
) { }
|
||||
|
||||
#if !NET8_0_OR_GREATER
|
||||
/// <summary>Provides the data binding target for the view</summary>
|
||||
public object DataContext {
|
||||
get { return this.dataContext; }
|
||||
set {
|
||||
if(value != this.dataContext) {
|
||||
object oldDataContext = this.dataContext;
|
||||
this.dataContext = value;
|
||||
OnDataContextChanged(this, oldDataContext, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
/// <summary>Called when the control's data context has changed</summary>
|
||||
/// <param name="arguments">Not used</param>
|
||||
protected override void OnDataContextChanged(EventArgs arguments) {
|
||||
object oldDataContext = this.dataContext;
|
||||
this.dataContext = base.DataContext;
|
||||
|
||||
if(this.dataContext != oldDataContext) {
|
||||
OnDataContextChanged(this, oldDataContext, this.dataContext);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// NOTE: Careful! On .NET 8.0, the Control class has its own DataContext,
|
||||
// but this one will be used to be able to report the previous one.
|
||||
/// <summary>Active data binding target, can be null</summary>
|
||||
private object dataContext;
|
||||
#endif
|
||||
/// <summary>Delegate for the OnViewModelPropertyChanged() method</summary>
|
||||
private PropertyChangedEventHandler onViewModelPropertyChangedDelegate;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue