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

MessageBox.Show from ViewModel? #12

Closed
acormier opened this issue May 22, 2014 · 4 comments
Closed

MessageBox.Show from ViewModel? #12

acormier opened this issue May 22, 2014 · 4 comments
Labels

Comments

@acormier
Copy link

Hi,
Trying to get my head around using RxUI. In
ReactiveUI.Samples / ReactiveUI.Samples.Commands / RxUI / MainVIewModel.cs
There's a call to MessageBox.Show(...). That seems wrong. Shouldn't that be in the view?

@arielbh
Copy link
Contributor

arielbh commented May 22, 2014

Basically you are right, but the samples are intended to show Rx in the most simple way possible.
You can hide the MessageBox beyond a service.

@anaisbetts
Copy link
Member

Definitely. One good MVVM-correct way to show message boxes is through the UserError framework, here's the docs on how that works

@acormier
Copy link
Author

Thanks. That's great info on errors.

What I was doing when I looked up this example was a command to open a file. It goes like this:

  • A btn is bound to a GetFilePath ReactiveCommand that's in the VM
  • from the view constructor: this.ViewModel.GetFilePath.Subscribe(_ => OpenFileDialog and pass file name to BLL.OpenFile)
  • BLL.OpenFile(fileName) (legacy code that I can't change) reads file and fires OnOpenFile event
  • handle OnOpenFile event in VM and add the content to a property that's bound to a Text control

I need to find the RxUI way of doing the last step but otherwise I hope I'm on the right track.

This is probably not the right place to post this ...
Thanks

@anaisbetts
Copy link
Member

Observable.FromEventPattern<STUFF,OTHERSTUFF>(x => OnOpenFile += x)
    .InvokeCommand(this, x => x.ViewModel.FileChosen);
FileChosen.Subscribe(x => {
    var file = (string)x;
    // Do a Thing
});

@lock lock bot added the outdated label Jun 24, 2019
@lock lock bot locked and limited conversation to collaborators Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants