Skip to content

tetrodoxin/WpfPlus.Plus

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF-Plus Toolkit

Modern flat themes and useful controls for your next WPF Application

License: MIT

Features:

  • flat dark and light styles for the most popular controls
  • highly customizable
  • custom Grid and StackPanel with adjustable column and row spacing
  • SimpleForm container to design forms easier than ever before
  • helper classes for easier MVVM implementation in conjunction with MVVM Light

Plus:

  • Alias markup extension, to define additional ReferenceKeys for existing references (may be external)
  • FlatResourceDictionary class, being a ResourceDictionary which 'unrolls' existing resource dictionaries, that contain nested resources, thus flattening a resource-tree to a resource list
  • ViewModelBase class, implementing INotifyPropertyChanged and rudimentary tracking for changed properties
  • ViewModelsCollection - a class for syncing a collection of model objects with a collection of associated view models
  • classes for implementing 'Delegate Commands", meaning objects that implement ICommand using delegates for the CanExecute() and Execute() methods
  • TextboxWatermarkBehavior - a WPF behavior for TextBox controls that realizes a Watermark text, that's visible (grayed) if the text box is empty
  • DragWindowAreaBehavior - a WPF behavior to mark a UI element as 'dragging area' for a window (just like the title bar of a window)

Download NuGet-Package

Screenshot Dark Theme Screenshot Light Theme

Install

Getting started is as simple as adding the WpfPlus.Plus NuGet-Package to your WPF project. You can do this in the NuGet-Package-Manager or manually:

PM> Install-Package WpfPlus.Plus

After that, one way to activate WpfPlus is to slightly edit your project's App.xaml to make it looking like this:

<Application x:Class="MyApplication.App"
             [...]
             xmlns:wpfPlus="clr-namespace:WpfPlus;assembly=WpfPlus"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <wpfPlus:DarkTheme />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

In case you like the light theme more you can also write <wpfPlus:LightTheme /> instead.

Alternatively, if you struggle with nested resource dictionaries or just want to use a Program.main() method, you may also do something like this:

App.xaml

<Application x:Class="MyApplication.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!-- Notice! no StartupUri here, if you use Program.main -->
    <Application.Resources />
</Application>

App.xaml.cs

public partial class App : Application
{
    internal App()
    {
        var isDark = true;      // or obtain the value somehow

        Resources.Clear();
        Resources.MergedDictionaries.Clear();

        if (isDark)
        {
            inhaleResourceDictionary(new WpfPlus.DarkTheme());
            inhaleResourceDictionary("ADDITIONAL_DARK_RESC.xaml");
        }
        else
        {
            inhaleResourceDictionary(new WpfPlus.LightTheme());
            inhaleResourceDictionary("ADDITIONAL_LIGHT_RESC.xaml");
        }

        inhaleResourceDictionary("ADDITIONAL_APP_RESC.xaml");            
    }

    private void inhaleResourceDictionary(string sourceUri)
        => Resources.MergedDictionaries.Add(
            new FlatResourceDictionary(
                sourceUri.Otherwise(s => !s.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase), $"{sourceUri}.xaml")
                ));

    private void inhaleResourceDictionary(ResourceDictionary dict)
        => Resources.MergedDictionaries.Add(
            new FlatResourceDictionary(dict));
}

Program.cs

public static class Program
{
    [STAThread]
    public static void Main(string[] args)
    {
        var app = new App();        // must be before MainWindow instantiation

        // you may also have a variant with view model here
        var window = new MainWindow();
        app.Run(window);
    }
}

Finally you can add Style="{DynamicResource FlatWindowStyle}" to any window that should apply the flat style.

That's it. Have fun!

About

Modern flat themes and useful controls for your next WPF Application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.6%
  • Smalltalk 0.4%