Skip to content
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

ReactiveWindow/ReactiveControl/etc non-nullable SafeViewModel property. #2646

Closed
HavenDV opened this issue Jan 13, 2021 · 4 comments · Fixed by #2758
Closed

ReactiveWindow/ReactiveControl/etc non-nullable SafeViewModel property. #2646

HavenDV opened this issue Jan 13, 2021 · 4 comments · Fixed by #2758

Comments

@HavenDV
Copy link
Contributor

HavenDV commented Jan 13, 2021

protected TViewModel SafeViewModel => ViewModel ?? throw new InvalidOperationException("ViewModel is null.");

This simplified usage of InvokeCommand:

// ViewModel produces a null reference warning and it needs to check.
InputTextBox
    .WhenKeyUp(Key.Enter)
    .InvokeCommand(SafeViewModel.Enter)
    .DisposeWith(disposable);
@glennawatson
Copy link
Contributor

try

.InvokeCommand(this, x => x.SafeViewModel.Enter)

@HavenDV
Copy link
Contributor Author

HavenDV commented Jan 13, 2021

image
It also produces the warning.

@ushenkodmitry
Copy link

x => x.ViewModel!.Enter

ChrisPulman added a commit that referenced this issue May 15, 2021
…method

Added Tests using a Nullable Viewmodel
Added nullability for ViewModel property in BindCommand
Proposed fix for #2646
glennawatson pushed a commit that referenced this issue May 15, 2021
…on (#2758)

Added Tests using a Nullable Viewmodel
Added nullability for ViewModel property in BindCommand
Proposed fix for #2646
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants