FeatureToggle Documentation


FeatureToggle can be installed via NuGet.

PM> Install-Package FeatureToggle

PM> Install-Package FeatureToggle.WPFExtensions

This will also install FeatureToggle.Core which is a PCL package.

Getting Started

1 Create a (strongly typed) toggle

Create a new class for each feature you want to toggle in your application.

This class needs to inherit from one of the FeatureToggle base classes (see list below).

This means feature toggling in the application can be dealt with in a strongly typed way.

public class MyAwesomeFeature : SimpleFeatureToggle {}

2 Configure the Toggle

The Toggle needs to get its enabled/disabled state from somewhere (unless you are using the AlwaysOffFeatureToggle or AlwaysOnFeatureToggle).

For Windows desktop applications and ASP.Net, the default place is in the app.config/web.config.

   <add key="FeatureToggle.MyAwesomeFeature" value="false" />

For Windows Phone and Windows Store apps, configuration is via entries in the app.xaml resources.

        <x:String x:Key="FeatureToggle.MyAwesomeFeature">true</x:String>        

In both cases, notice the “FeatureToggle.” prefix that is expected before the name of your Toggle (which is the name of your Toggle class).

3 Use the toggle in code:

var myAwesomeFeature = new MyAwesomeFeature ();

if (!myAwesomeFeature.FeatureEnabled)  
   // code to disable stuff (e.g. UI buttons, etc)

Or in XAML (if you’ve installed the FeatureToggle.WPFExtensions package):

<Button Visibility="{Binding Path=MyAwesomeFeature, Converter={StaticResource toggleVisibilityConverter} }">My Awesome Feature</Button>

Bundled Toggles

There are a number of Toggles that come bundled with FeatureToggle

You can also customize FeatureToggle in a number of ways.

There are also a number of decorators to wrap toggles and add additional features:

Using the Bundled Toggles


Create a Toggle for the feature you want to control by inheriting from SimpleFeatureToggle - there’s no need to override anything:

private class SaveToPdfFeatureToggle : SimpleFeatureToggle { }

Add an entry to your AppSettings or Application.Resources to control the value of the SaveToPdfFeatureToggle:

   <add key="FeatureToggle.SaveToPdfFeatureToggle" value="true"/>

        <x:String x:Key="FeatureToggle.SaveToPdfFeatureToggle">true</x:String>        

Again, note the convention FeatureToggle.class name

Now you can use the Toggle in code:

var savePdfFeature= new SaveToPdfFeatureToggle();
if (savePdfFeature.FeatureEnabled)

To disable the Toggle, just set the configured value to false.

AlwaysOffFeatureToggle and AlwaysOnFeatureToggle

These toggle are not configurable they are either always on or off.

Create a Toggle for the feature you want to control by inheriting from AlwaysOffFeatureToggle or AlwaysOnFeatureToggle.

private class SaveToPdfFeatureToggle : AlwaysOffFeatureToggle { }

Now you can use the Toggle in code (or XAML binding):

var savePdfFeature= new SaveToPdfFeatureToggle();
if (savePdfFeature.FeatureEnabled)

EnabledOnOrAfterDateFeatureToggle and EnabledOnOrBeforeDateFeatureToggle

Create a Toggle for the feature you want to control by inheriting from EnabledOnOrAfterDateFeatureToggle or EnabledOnOrBeforeDateFeatureToggle.

private class SaveToPdfFeatureToggle : EnabledOnOrAfterDateFeatureToggle { }

Add an entry to your AppSettings or Application.Resources:

   <add key="FeatureToggle.SaveToPdfFeatureToggle" value="01-Jan-2000 18:00:00"/>

        <x:String x:Key="FeatureToggle.SaveToPdfFeatureToggle">01-Jan-2000 18:00:00</x:String>        

Notice the expected datetime format: dd-MMM-yyyy HH:mm:ss

Then use in the same way as other toggles.


Create a Toggle for the feature you want to control by inheriting from EnabledBetweenDatesFeatureToggle.

private class SaveToPdfFeatureToggle : EnabledBetweenDatesFeatureToggle { }
Add an entry to your config int he format (start date end date)
   <add key="FeatureToggle.SaveToPdfFeatureToggle " value="01-Jan-2000 00:00:00 | 01-Feb-2000 00:00:00"/>

        <x:String x:Key="FeatureToggle.SaveToPdfFeatureToggle">01-Jan-2000 00:00:00 | 01-Feb-2000 00:00:00</x:String>        

Again notice the expected datetime format: dd-MMM-yyyy HH:mm:ss


This toggle is not available on Windows Phone or Windows Store apps.

This Toggle gets it’s value from a Sql Server database. You can use to enable a Feature from a single point when the Feature spans a number of applications, services, layers, etc.

Create a Toggle for the feature you want to control by inheriting from SqlFeatureToggle:

private class SaveToPdfFeatureToggle : SqlFeatureToggle{ }

Add an entries to your AppSettings section for the Sql Server database connection string and a sql statement that returns either “true” or “false” from a SQL Server bit field.

<add key="FeatureToggle.SaveToPdfFeatureToggle.ConnectionString" value="Data Source=.\SQLEXPRESS;Initial Catalog=FeatureToggleDatabase;Integrated Security=True;Pooling=False"/>
<add key="FeatureToggle.SaveToPdfFeatureToggle.SqlStatement" value="select Value from Toggle where ToggleName = 'SaveToPdfFeatureToggle'"/>

From v3.1 the connection string can be specified in the section without the postfixed ".ConnectionString" as shown below:

	<add name="FeatureToggle.MySqlServerToggleFalse" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=FeatureToggleIntegrationTests;Integrated Security=True;Pooling=False" />    

From v3.2 a named can be created with an arbitrary name, and this can referenced from multiple toggle configurations.

To do this first create a connection:

    <add name="myAwesomeConnection" connectionString="connection string to db here" />

Then add an appSettings entry, with the name of the toggle, plus “.ConnectionStringName”. The value here points to the named connectionString:

    <add key="FeatureToggle.MyFeatureToggle.ConnectionStringName" value="myAwesomeConnection" />


This toggle requires no configuration, it will randomly enable or disable a feature.


This toggle will be enabled on specified days of the week.

Configuration for this toggle requires week days to be specified in long format, e.g.

<add key="FeatureToggle.MondayAndFridayToggle" value="Monday, Friday"/>

or in XAML:

<system:String  x:Key="FeatureToggle.FridayImInLoveFeature">Friday</system:String>


This toggle is not available on Windows Phone or Windows Store apps.

This toggle get it’s value from a RavenDB database.

Create a Toggle for the feature you want to control by inheriting from BooleanRavenDBFeatureToggle:

private class SaveToPdfFeatureToggle : BooleanRavenDBFeatureToggle{ }

Add RavenDB connection string to app/web config:

	<add name="FeatureToggle.SaveToPdfFeatureToggle" connectionString="Url = http://localhost:8080;database=FeatureToggleInterationTests"/>    

The database should contain a collection called “BooleanToggleSettings” with a document for every toggle that contains a property “Enabled”:

  "Enabled": true

Check out the test setup to see an example of writing some toggle config entries.


This toggle gets it’s enabled state from a JSON HTTP endpoint.

Configuration should be the url where the JSON configuration lives, e.g:

<add key="FeatureToggle.HttpJsonTrueToggle" value="http://localhost:8084/api/test/getenabled" />

As with all the toggles, if url is not available then an exception will be raised, rather than assuming either enabled or disabled.

The expected JSON that should be returned is in the form:

{"enabled": true}


{"enabled": false}

XAML Binding - WPF, Windows Phone and Windows Store

Binding the Visibility of a UI Element to a Toggle

Create a Toggle as described above.

For a WPF application install the FeatureToggle.WFPExtensions NuGet package.

Windows Phone and Windows Store have it build in to the NuGet package.

In your XAML declare a converter:

<Wpf:FeatureToggleToVisibilityConverter x:Key="toggleVisibilityConverter"/>

Create a property in your view-model or code-behind:

public IFeatureToggle SaveToPdfFeature
      return _saveToPdfFeature;
      _saveToPdfFeature = value;
      // Do INotifyPropertyChanged stuff here if required

Now bind your UI elements visibility:

<Button Visibility="{Binding Path=SaveToPdfFeature, Converter={StaticResource toggleVisibilityConverter} }">Save To PDF</Button>

About Jason Roberts

Jason Roberts is a Microsoft MVP, Pluralsight course author and Journeyman Software Developer with over 12 years experience.

He is the author of the books Keeping Software Soft and C# Tips and writes at his blog DontCodeTired.com.