Skip to content

mrousavy/Jellyfish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jellyfish

AppVeyor badge NuGet downloads badge
Buy Me a Coffee at ko-fi.com

🐟

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

Usage

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.

πŸ“ View Models

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 πŸ“–

⚑ Commands

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 πŸ“–

πŸ’‰ Dependency Injection

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();
    }
}

See Dependency Injection πŸ“–

πŸ’Ύ Enums

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 πŸ“–

βš™οΈ Preferences

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 πŸ“–

πŸ”” Feeds

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 πŸ“–

Results

With Jellyfish

public class LoginViewModel : ViewModel
{
    private User _user;
    public User User
    {
        get => _user;
        set => Set(ref _user, value);
    }
}

Without Jellyfish

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");
	}
    }
}