An incredibly light and type safe MVVM library for .NET WPF, Silverlight, Xamarin and UWP
Jellyfish is on NuGet:
PM> Install-Package Jellyfish
Make sure to also check out the Jellyfish Visual Studio Extension π¦!
Compared to other MVVM Frameworks like MVVM Light, Prism or Caliburn.Micro, this framework is
- as light as possible
- using modern best-practices
- using modern code style
- using little to no runtime reflection to be as fast as possible
- exactly fitting my needs
For description, documentation and usage, please view the Jellyfish wiki π or the Getting Started guide π. For usage-example projects, please see Jellyfish.Demo or GameFinder.
Every ViewModel needs to implement the ViewModel
class:
public class LoginViewModel : ViewModel
{
private User _user;
public User User
{
get => _user;
set => Set(ref _user, value);
}
}
See View Models π
The RelayCommand
is an ICommand
implementation.
<Window ...>
<Button Command="{Binding LoginCommand}" />
</Window>
Initialize the ICommand
with a non-generic RelayCommand
instance and the given action/callback:
ICommand LoginCommand = new RelayCommand(LoginAction, CanLogin);
// ...
void LoginAction(object parameter)
{ ... }
bool CanLogin(object parameter)
{ ... }
See Commands π
Provide dependencies for types using the IInjector
At app startup:
Injector.Register<IUser>(() => new User("John", "Smith"));
Injector.Register<IDatabaseService>(() => OpenDatabaseService(username, password));
Some ViewModel:
class LoginViewModel : ViewModel
{
IUser User { get; set; }
IDatabaseService _service;
LoginViewModel()
{
this.Inject();
}
}
The enum binding source extension allows for better binding support on enums.
Just use the EnumBindingSource
extension to bind an enum to any ItemsSource
:
<ComboBox ItemsSource="{Binding Source={jellyfish:EnumBindingSource {x:Type local:Status}}}"
SelectedItem="{Binding SelectedStatus}" />
See Enums π
An abstract class definition for any application Preferences
.
public class DemoPreferences : Preferences
{
public int SomeInt { get; set; } = 400;
public string SomeString { get; set; } = "test string";
public bool SomeBool { get; set; } = false;
public object SomeObject { get; set; } = new
{
Name = "Marc",
IsValid = true
};
}
See Preferences π
The IFeed<T>
allows notifying any subscribers in this feed about sudden changes within the application domain in realtime.
class CustomViewModel : INode<NotifyReason>
{
public CustomViewModel
{
this.Subscribe();
}
public void MessageReceived(NotifyReason reason)
{ ... }
}
Feed.Notify(NotifyReason.RefreshView);
See Feeds π
public class LoginViewModel : ViewModel
{
private User _user;
public User User
{
get => _user;
set => Set(ref _user, value);
}
}
public class LoginViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
private string _username;
public string Username
{
get
{
return _username;
}
set
{
_username = value;
OnPropertyChanged("Username");
}
}
}