-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Developers Bypass the Default Fallback Behavior (resolves #3713) #3718
Allow Developers Bypass the Default Fallback Behavior (resolves #3713) #3718
Conversation
…iveui#3713) This changes applys to the Maui/Wpf/XamarinForm platform.
The win forms scenario likely we do want the property added but keep the default the same as current win form functionality. |
Fine. And should I also add a new method of |
Yeah. Make it all consistent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rerun the tests and update the verified files in the API checks, thank you.
Sorry, at that time, the api vertified tests always failed if I didn't add the following API to verified.txt. :
I don't known why the VS generated this However, it's quite strange that when I try to add the Anyway, I'll remove them from the verified.txt later together with the commits for WinForm |
@glennawatson are you able to merge this then do another PR to fix the 6 API files that are are failing. |
Believe @newbienewbie is still working on the PR at the moment with some winforms changes |
Hi, I'm currently blocked. I find the current WinForm's behavior is quite different from the WPF's. CacheViewsThe WinForm's implementation has a unique if (CacheViews)
{
// when caching views, check the current viewmodel and type
var c = _content as IViewFor;
if (c?.ViewModel is not null && c.ViewModel.GetType() == viewModel?.GetType())
{
c.ViewModel = viewModel;
// return early here after setting the viewmodel
// allowing the view to update it's bindings
return;
}
} At the same time, the ViewContractObservable = Observable.Return(string.Empty); In the case where I have An easy way is the asumming the DefaultContentThe WinForm applies the DefaultContent only if ViewModel is null and won't assign the if (ViewModel is null) // ********************* the DefaultContent is applied only if ViewModel is NULL******************
{
if (DefaultContent is not null)
{
Content = DefaultContent;
}
return;
}
if (CacheViews)
{
// ...
}
var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
var view = viewLocator.ResolveView(x.ViewModel, x.Contract);
if (view is not null) // ********************* change the content only if view is not null ************************
{
view.ViewModel = x.ViewModel;
Content = view;
} While the WPF will set the if (viewModel is null)
{
Content = DefaultContent;
return;
}
...
if (viewInstance is null)
{
Content = DefaultContent;
this.Log().Warn($"The {nameof(ViewModelViewHost)} could not find a valid view for the view model of type {viewModel.GetType()} and value {viewModel}.");
return;
} My concern is: in a WinForm App, if I dynamically change the ViewContractObservable to a contract that is not registered before (e.g. "Contract_That_Doesnot_Exist"), the above I don't know how to go futher without breaking existing behavoir. |
Let's just keep winforms as is at the moment. Maybe open a issue with your findings and next major release we can consider changing the functionality. that also allows time for users to see if the new functionality etc. |
I open a discussion and describe the inconsistent behavior of DefaultContent that blocks me. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3718 +/- ##
==========================================
+ Coverage 58.31% 58.44% +0.12%
==========================================
Files 160 160
Lines 5842 5847 +5
Branches 1031 1031
==========================================
+ Hits 3407 3417 +10
+ Misses 2046 2042 -4
+ Partials 389 388 -1 ☔ View full report in Codecov by Sentry. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This changes applys to the Maui/Wpf/XamarinForm platform.
What kind of change does this PR introduce?
What is the current behavior?
ViewContract
condition if nothing found.What is the new behavior?
ContractFallbackByPass
so that we can bypass this fallback behavior.protected virtual void ResolveViewForViewModel(object? viewModel, string? contract)
, which allows developers override this behavior.What might this PR break?
As far as I can see, it does not break anying.
Please check if the PR fulfills these requirements
Other information:
For WPF/MAUI/XamForms/WinUI, the
ContractFallbackByPass
is set to false by default. So it won't breaking existing apps.However, I find the current WinForms implementation has no default fallback behaivor as same as WPF
So I didn't add such a property for WinForms. Is it better to add such a property that is set to true by default ?