This must be the best explanation I came across so far. But I'd like to come up with two questions: 1. Why is your view of type usercontrol? Could I also use a window instead? What would I have to change? 2. Since I'm new to wpf - if you click on "OK", or "YES" / "NO" in the dialogs, the dialogs dont't close. How do I achieve this? Thanks, and please keep making those videos!
Is it correct from the MVVM perspective to create one ViewModel inside another(personally I think that your implementation is pretty good and due to composition (one ViewModel inside another) there should not be any problems with coupling)? This makes the return of some from OpenDialog useless 'cause we can just get that result using ViewModel instance
Thank you for uploading. Just a quick question: If my viewModel inherits from DialogViewModelBase, it won't accept my NotifyPropertyChangedBase, since a class can only have one base class. Since I'm new to MVVM, and WPF in general: how would I resolve this? I know, there's tons of info around in the www, but you really know how to explain things!
This is a simple alert and YesNo dialog. What about if I want to show a complex dialog that need another service like a DataService and I need to pass it with dependency injection through the constructer. How to do that in a testable way ?? PS: I did it but my solution is not testable i.e I am explicitly working with the view and the container in the ViewModel !!!
I had the same issue, he does not explain it at all! Unfortunately you have to go to his github and dig for it in the SimpleWPF master... I only got it to compile after a bunch of work!
i followed the tutorial, my hurdle is when the dialog box opens, the ContentControl just shows the class name, *WpfApp1.Dialogs.Alert.AlertDialogViewModel* instead of the message and button i've gone through the AlertDialogView and DialogWindow many times i cannot see any difference.. my own thought is i'm trying this in .NET Core vs .NET Framework any suggestions?
This must be the best explanation I came across so far. But I'd like to come up with two questions:
1. Why is your view of type usercontrol? Could I also use a window instead? What would I have to change?
2. Since I'm new to wpf - if you click on "OK", or "YES" / "NO" in the dialogs, the dialogs dont't close. How do I achieve this?
Thanks, and please keep making those videos!
Is it correct from the MVVM perspective to create one ViewModel inside another(personally I think that your implementation is pretty good and due to composition (one ViewModel inside another) there should not be any problems with coupling)? This makes the return of some from OpenDialog useless 'cause we can just get that result using ViewModel instance
Thank you for uploading. Just a quick question: If my viewModel inherits from DialogViewModelBase, it won't accept my NotifyPropertyChangedBase, since a class can only have one base class. Since I'm new to MVVM, and WPF in general: how would I resolve this? I know, there's tons of info around in the www, but you really know how to explain things!
how is the dialogs closed when the "Yes", "No", or "OK" button is pressed? I'm confused since I haven't seen any .Close() here.
I had the same question, but apparently setting DialogResult property triggers a Close() method
This is a simple alert and YesNo dialog. What about if I want to show a complex dialog that need another service like a DataService and I need to pass it with dependency injection through the constructer. How to do that in a testable way ?? PS: I did it but my solution is not testable i.e I am explicitly working with the view and the container in the ViewModel !!!
could you please share the specific RelayCommand implementation you are using? thank you. Great Video!
I had the same issue, he does not explain it at all!
Unfortunately you have to go to his github and dig for it in the SimpleWPF master... I only got it to compile after a bunch of work!
using System;
using System.Windows.Input;
namespace SimpleWPF.Input
{
///
/// A command implementation
///
///
public class RelayCommand : ICommand
{
private readonly Action _execute = null;
private readonly Func _canExecute = null;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public RelayCommand(Action execute, Func canExecute = null)
{
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute ?? (_ => true);
}
public bool CanExecute(object parameter) => _canExecute((T)parameter);
public void Execute(object parameter) => _execute((T)parameter);
}
public class RelayCommand : RelayCommand
{
public RelayCommand(Action execute)
: base(_ => execute()) { }
public RelayCommand(Action execute, Func canExecute)
: base(_ => execute(), _ => canExecute()) { }
}
}
@@283518 thanx so much+
@@283518 does not work canExecute = canExecute ?? ( => true);
i followed the tutorial, my hurdle is when the dialog box opens, the ContentControl just shows the class name, *WpfApp1.Dialogs.Alert.AlertDialogViewModel* instead of the message and button
i've gone through the AlertDialogView and DialogWindow many times i cannot see any difference.. my own thought is i'm trying this in .NET Core vs .NET Framework
any suggestions?
Found it!
needed to added a OnStartup override to App.xml, and *DataTemplateManager*
Is it recommended to use Window control as modals or dialogs in a Custom Control Library?. Thanks in advance.
well sorry if i sound stupid because i just started approaching WPF but...
do you really need 25 mins to make a yes-no dialogue ?
Explain and code in the correct way, take a little time dude
does anyone know how to return the dialog results into a variable in the main window file? (not the MainWindowViewModel)
great work
but why this MVVm is so complicaed
just to show a dialog we have to go all that way
Your Github link doesn't work, can you please fix?
Nicely done. Thank you!
RelayCommand in tutorial not working at all
Github link is not working.
Nice video bro.. help me a lot!
Good Job
Good!
Anyone has the implementation of relayCommand? and the generic one?
Get it from here github.com/Joben28/SimpleWPF
using System;
using System.Windows.Input;
namespace SimpleWPF.Input
{
///
/// A command implementation
///
///
public class RelayCommand : ICommand
{
private readonly Action _execute = null;
private readonly Func _canExecute = null;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public RelayCommand(Action execute, Func canExecute = null)
{
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute ?? (_ => true);
}
public bool CanExecute(object parameter) => _canExecute((T)parameter);
public void Execute(object parameter) => _execute((T)parameter);
}
public class RelayCommand : RelayCommand
{
public RelayCommand(Action execute)
: base(_ => execute()) { }
public RelayCommand(Action execute, Func canExecute)
: base(_ => execute(), _ => canExecute()) { }
}
}
Good content, but there's a lot of good questions not answered here in the comments. That means something...