Giter Site home page Giter Site logo

chrispulman / crisscross Goto Github PK

View Code? Open in Web Editor NEW
29.0 1.0 2.0 11.96 MB

A Navigation Framework for ReactiveUI based projects

License: MIT License

C# 99.61% CSS 0.06% HTML 0.04% JavaScript 0.02% Batchfile 0.01% PowerShell 0.14% Shell 0.12%
avalonia maui reactiveui wpf xamarin webview2

crisscross's Introduction

CrissCross

A Navigation Framework for ReactiveUI based projects

Alt

CrissCross

CrissCross CI-Build

What is CrissCross?

CrissCross is a navigation framework for ReactiveUI based projects. It is designed to be used with ReactiveUI, but could be adapted to be used with any MVVM framework.

Why CrissCross?

CrissCross is designed to be a simple, lightweight, and easy to use navigation framework. It is designed to be used with ReactiveUI.

How do I use CrissCross?

Step 1: Install CrissCross

CrissCross is available on NuGet. You can install it using the NuGet Package Manager:

Nuget Nuget

Install-Package CrissCross

or Nuget Nuget

Install-Package CrissCross.WPF

or Nuget Nuget

Install-Package CrissCross.XamForms

or Nuget Nuget

Install-Package CrissCross.MAUI

or Nuget Nuget

Install-Package CrissCross.Avalonia

or Nuget Nuget

Install-Package CrissCross.WinForms

Step 2: Create a ViewModel

Create a ViewModel that inherits from RxObject. This is the ViewModel that will be used for the MainWindow.

    public class MainWindowViewModel : RxObject
    {
        public MainWindowViewModel()
        {
            this.BuildComplete(() =>
            {
                // Do something when the IOC Container is built
            });

            // Setup the IOC Container
            Locator.CurrentMutable.RegisterConstant<MainViewModel>(new());
            Locator.CurrentMutable.Register<IViewFor<MainViewModel>>(() => new MainView());

            Locator.CurrentMutable.RegisterConstant<FirstViewModel>(new());
            Locator.CurrentMutable.Register<IViewFor<FirstViewModel>>(() => new FirstView());
            
            // Notify the application that the IOC Container that it is complete and ready to use.
            Locator.CurrentMutable.SetupComplete();
        }
    }

Step 3: Create a View

Create a View that inherits from NavigationWindow. This is the View that will be used for the MainWindow. add xmlns:rxNav="https://github.com/ChrisPulman/CrissCross" to the Window inherits in XAML. Change Window to rxNav:NavigationWindow in XAML. Add x:TypeArguments="local:MainWindowViewModel"

    public partial class MainWindow : NavigationWindow<MainWindowViewModel>
    {
        public MainWindow()
        {
            // Remember to set x:Name in XAML to "mainWindow"
            InitializeComponent();
            
            this.WhenActivated(disposables =>
            {
                // Do something when the View is activated

                // Configure the Navigation for the MainWindow
                NavBack.Command = ReactiveCommand.Create(() => this.NavigateBack(), CanNavigateBack).DisposeWith(d);
                
                // Navigate to the MainViewModel
                this.NavigateToView<MainViewModel>();
            });
        }
    }

Step 4: Create a ViewModel

Create a ViewModel that inherits from RxObject. This is the ViewModel that will be used for the MainView.

    public class MainViewModel : RxObject
    {
        public MainViewModel()
        {
            this.BuildComplete(() =>
            {
                // Do something when the IOC Container is built

                // Configure the Navigation for the MainViewModel using, you will pass the name of the Navigation Host Window that you want to navigate with.
                this.NavigateBack("mainWindow")
                this.CanNavigateBack("mainWindow")
                this.NavigateToView<FirstViewModel>("mainWindow")
            });
        }
    }

Step 5: Create a View

Create a View that inherits from ReactiveUserControl. This is the View that will be used for the MainView.

    public partial class MainView : ReactiveUserControl<MainViewModel>
    {
        public MainView()
        {
            InitializeComponent();

            this.WhenActivated(disposables =>
            {
                // Do something when the View is activated
            });
        }
    }

Step 6: For WPF Applications Configure Single Instance Application if required

If you want to prevent multiple instances of the application from running at the same time, you can use the Make.SingleInstance method.

    protected override void OnStartup(StartupEventArgs e)
    {
        // This will prevent multiple instances of the application from running at the same time.
        Make.SingleInstance("MyUniqueAppName ddd81fc8-9107-4e33-b848-cac4c3ec3d2a");
        base.OnStartup(e);
    }

Step 7: Run the application

Run the application and you should see the MainView.

Avalonia

Step 1: Install CrissCross

CrissCross is available on NuGet. You can install it using the NuGet Package Manager:

Install-Package CrissCross.Avalonia

Step 2: Create a ViewModel

Create a ViewModel that inherits from RxObject. This is the ViewModel that will be used for the MainWindow.

    public class MainWindowViewModel : RxObject
    {
        public MainWindowViewModel()
        {
            this.BuildComplete(() =>
            {
                // Do something when the IOC Container is built
            });

            // Setup the IOC Container
            Locator.CurrentMutable.RegisterConstant<MainViewModel>(new());
            Locator.CurrentMutable.Register<IViewFor<MainViewModel>>(() => new MainView());

            Locator.CurrentMutable.RegisterConstant<FirstViewModel>(new());
            Locator.CurrentMutable.Register<IViewFor<FirstViewModel>>(() => new FirstView());
            
            // Notify the application that the IOC Container that it is complete and ready to use.
            Locator.CurrentMutable.SetupComplete();
        }
    }

Step 3: Create a NavigationView

Create a View that inherits from NavigationWindow OR NavigationUserControl. This is the View that will be used for the MainWindow. add xmlns:rxNav="https://github.com/ChrisPulman/CrissCross" Change Window to rxNav:NavigationWindow in XAML. OR Change UserControl to rxNav:NavigationUserControl in XAML.

As Avalonia has two modes of operation you will need to select the correct mode for your application.

    public partial class MainWindow : NavigationWindow<MainWindowViewModel>
    {
        public MainWindow()
        {
            // Remember to set x:Name in XAML to "mainWindow"
            InitializeComponent();
            
            this.WhenActivated(disposables =>
            {
                // Do something when the View is activated

                // Configure the Navigation for the MainWindow
                NavBack.Command = ReactiveCommand.Create(() => this.NavigateBack(), CanNavigateBack).DisposeWith(d);
                
                // Navigate to the MainViewModel
                this.NavigateToView<MainViewModel>();
            });
        }
    }

Step 4: Create a ViewModel

Create a ViewModel that inherits from RxObject. This is the ViewModel that will be used for the MainView.

    public class MainViewModel : RxObject
    {
        public MainViewModel()
        {
            this.BuildComplete(() =>
            {
                // Do something when the IOC Container is built

                // Configure the Navigation for the MainViewModel using, you will pass the name of the Navigation Host Window that you want to navigate with.
                this.NavigateBack("mainWindow")
                this.CanNavigateBack("mainWindow")
                this.NavigateToView<FirstViewModel>("mainWindow")
            });
        }
    }

Step 5: Create a View

Create a View that inherits from ReactiveUserControl. This is the View that will be used for the MainView.

    public partial class MainView : ReactiveUserControl<MainViewModel>
    {
        public MainView()
        {
            InitializeComponent();

            this.WhenActivated(disposables =>
            {
                // Do something when the View is activated
            });
        }
    }

crisscross's People

Contributors

chrispulman avatar dependabot[bot] avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

crisscross's Issues

Problem with WebView2 overlayed button images displaying

First off....I can't thank you enough for making this repo available! I've been fighting this problem for months, getting any control to overlay the WebView2 control. Your code works great.

All of my buttons (for my project) are transparent, with a child image for what the button does. Images are PNG with transparency.

The images will not display at all unless I set Background="(any color excluding Transparent)".

This isn't a huge problem, as the button is still overlaid properly.

I've tried JPG and GIF, all do the same thing. Image is invisible until a background color is set.

Let's call it minor (cosmetic) :D

Project is a desktop WPF app with net6.0-windows running on W10Ent

Thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.