# Implementing Themes with Wisej.NET

*by* [*Jon Hilton*](https://www.learnwisej.net/authors/jon-hilton)

Implementing features is one thing, making them look good is quite another!

It's important for any framework to have a good story around styling and theming your app, and WiseJ.NET has a dedicated Theme Builder to make this easier.

Let's see how it works.

The first step is to [download and run the Theme Builder application](https://wisej.com/theme-builder/).

The download includes a single zip file, in which you'll find a file called Wisej.ThemeBuilder.exe.

Launch that and you'll find yourself looking at the Theme Builder UI.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2F4L1QNKbg5k6STTXaomrE%2Fimage.png?alt=media&#x26;token=1fdcccf1-cb3f-4adc-93b1-ebeb9a00acca" alt=""><figcaption><p>Wisej.NET Theme Builder UI with various panels open, listing aspects of the theme which you can tweak. On the right is a preview of how the current theme will look when applied to your components/pages.</p></figcaption></figure>

At the top of this screen you can see the currently selected theme (Boostrap-4 in this case).

In the top left pane you'll see a detailed list of all the things you can tweak for the current theme.

There you'll find Colors, Images, Fonts, and **Appearances**.

In the **Appearances** section you'll find every Wisej.NET component.

Buttons, ComboBoxes, ScrollBars are all available to be styled from this menu.

When you click on an appearance you'll see it's properties in the bottom left pane.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FATBuiTBbOru84OdAH6Vd%2Fimage.png?alt=media&#x26;token=58020636-7ef3-4514-bd2e-f31b8c4aaf6a" alt=""><figcaption></figcaption></figure>

Here I've selected **Button** and we can see various properties which can be tweaked, including the button's text color, opacity, text alignment.

The preview pane on the right shows, in real time, how your tweaks affect the visible controls.

All the controls in the preview pane can be clicked, which will select the relevant appearance in the pane on the left.

Not all controls are shown in the preview window, but you can get to them if you select the **Controls** tab in the menu above the preview pane.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FzqFlAbkrRM9Zsg6ZEeqG%2Fimage.png?alt=media&#x26;token=971bdffb-6b78-4dd3-aecc-4a61c002c23d" alt=""><figcaption><p>Controls tab showing more controls which can be styled</p></figcaption></figure>

### Simple tweaks to the existing styles

Let's start with a really simple tweak to the existing button style.

First we can locate the **Button** appearance in the **Components** pane.

Once there we can select one of its states.

We'll explore states in a moment, but for now we'll make our changes to the **Default** state.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FtTJB9PcY86XXs2qfJL6v%2Fimage.png?alt=media&#x26;token=11daf1ff-e1d7-4b90-b786-55fc394d4b6c" alt=""><figcaption></figcaption></figure>

With **Button > Default** selected we see its specific styles in the **Properties** pane.

It's then possible to tweak those individual styles/properties.

Here I've changed the **backgroundColor** style to make buttons yellow by default.

We'll see how to test and use this updated theme in a moment, but first let's take a quick look at component states.

### Customising components with multiple states

Let's explore states with the help of another component, the **MessageBox**.

With the **Controls** tab open in the preview pane you'll see the first few controls are various different types of Message Box.

Click on one of those and it will be automatically selected in the **Components** pane where we can then see all its properties/styles.

In this context states refer to the different types of Message Box we can show (error, information, stop etc.)

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FyCZY7RwUGDsliXuSgbf0%2Fimage.png?alt=media&#x26;token=7e268ab5-eda4-41be-91e7-68f3ea81ccaa" alt=""><figcaption></figcaption></figure>

We can see the different background colors specified for each state.

Let's tweak the background color for the **information** state.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FF5oyUTtq8CsfqEapmgvp%2Fimage.png?alt=media&#x26;token=9f98dd78-9cf9-416a-8c1c-6f409b851995" alt=""><figcaption></figcaption></figure>

As soon as we do that, we can see from the preview that our Message Box now has a bit of a color clash going on!

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FuCvkjPdhPJg11jNluYJh%2Fimage.png?alt=media&#x26;token=1bee63e9-829e-4d10-bbf0-1e03c12b7426" alt=""><figcaption></figcaption></figure>

The text and icon colors could do with a tweak.

The easiest way to identify which appearance needs changing is to click on the element in the preview pane.

In this case, clicking on the title (the "Message Box" text) highlights the **MessageBox > Title** appearance.

Now we can clearly see that the property we want to tweak for the **information** state is **properties > textColor**.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FORIAeo5VgU6Snibe3qz4%2Fimage.png?alt=media&#x26;token=3b35d484-ffcd-463c-b403-0c1c8fc067c6" alt=""><figcaption></figcaption></figure>

Let's go ahead and change that.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FLKfi0apWMlLXDJF34DJp%2Fimage.png?alt=media&#x26;token=11d5b09b-08f8-4d5e-a056-d31b60a0c0c6" alt=""><figcaption></figcaption></figure>

We can do the same with the Image  (exclamation), and the CaptionBar (the bar underneath the title).

By the time we're done we've changed these appearances (all for the **information** state):

* MessageBox > Title
* MessageBox > Image
* MessageBox > CaptionBar

Now we're close to a style we could run with (albeit we won't be winning any style awards for this one!)

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FVYd3Tqq33YaMtvMeeQta%2Fimage.png?alt=media&#x26;token=e4274a59-8c84-4b18-9667-051dd4f248e6" alt=""><figcaption></figcaption></figure>

But what about that message text?

If we click the text in the preview pane we'll see **MessageBox > Message** highlighted in the left-hand pane.

But, unlike the other appearances, this one has no alternative state for **Information**, just the **Default** state.

The good news is we can add our own additional state(s).

First by clicking the + icon in the top left corner of the **Components** pane.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FysOwy3QRsPytdQb4w7iq%2Fimage.png?alt=media&#x26;token=92776350-5e88-4a9f-96d2-991262c62562" alt=""><figcaption></figcaption></figure>

In the resulting window we can select the **State** tab, then type in the name, which in this case needs to be **Information**.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2F2zF2DtM16b9u3u6oVb8g%2Fimage.png?alt=media&#x26;token=828700a6-7633-4b80-844c-e804ce8b7c91" alt=""><figcaption></figcaption></figure>

Then click **OK** to add the new State.

Now we can add a new property to this state.

First, select **properties** in the **Properties** pane, then click the + icon.&#x20;

We see the **Add Style/Property** dialog.

We can select the property name **textColor** and give it a value (in this case, the color we want).

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FadE81s5x4Elsw596GejY%2Fimage.png?alt=media&#x26;token=2056a1df-ad92-4280-8a35-506442baf18b" alt=""><figcaption></figcaption></figure>

Click **OK** and the preview will update to show how the message box looks with our new properties applied.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FSHPC2xPjxi3OmUu9Aqzy%2Fimage.png?alt=media&#x26;token=20f1722f-7e84-436a-90d6-117bdfdae0e7" alt=""><figcaption></figcaption></figure>

### I have a new theme and I'm not afraid to use it!

So far so good, but how to actually use this new style we've defined?

The first step is to save it.&#x20;

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FUFrStCHHfnNU0VLSkiUb%2Fimage.png?alt=media&#x26;token=de5fd0a8-06bd-49a4-8ec6-f5553e855db1" alt=""><figcaption></figcaption></figure>

Click the **Save As** icon (the save icon with a pencil over it) to save your theme somewhere on your machine as a .theme file.

#### Use your custom theme during development

In Visual Studio, in a new or existing Wisej.NET project you'll see a **Themes** folder.

Right click that, then select Add > Existing Item.

Locate your newly saved theme, and click **OK** to add it to the **Themes** folder.

Once done, it should look something like this:

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FmmHnZXD421uwjsZQf45I%2Fimage.png?alt=media&#x26;token=3149784a-88d9-430b-862e-a229b58a6eae" alt=""><figcaption></figcaption></figure>

With this we can use this theme when viewing components in the designer.

For example, here's a simple page with a button.

Notice how, with the correct theme selected in the bottom left, the buttons have picked up the new style (yellow background).

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FEUyajPKvq42DGpMQBHF4%2Fimage.png?alt=media&#x26;token=3cc9c21b-d986-45b5-8eac-6cf0eb8129be" alt=""><figcaption></figcaption></figure>

This works for development, but if you launch and view your app in the browser it isn't (yet) using the new theme.

For that we need to tweak the application config.

#### Use your custom theme at runtime

There are a few ways to select which theme your running Wisej.NET app uses.

You can configure it in your application's **Default.json.**&#x20;

```json
{
    "url": "Default.html",
    "startup": "WisejTutorials.Program.Main, WisejTutorials",
    "theme": "WisejTheme" // add this
}
```

Another way is via **web.config**.

```markup
<configuration>
	<appSettings>
		...		
		<add key="Wisej.DefaultTheme" value="WiseJTheme"/>
	</appSettings>
	...
</configuration>
```

Either of these approaches will set the theme for the entire app.

Finally, you can also switch theme programmatically, while your app is running:

```csharp
private void btnChangeTheme_Click(object sender, EventArgs e)
{
    Application.LoadTheme("WisejTheme");
}
```

Now we know how to create and use themes, there's one thing left to explore; how to define brand new styles from scratch.

But before we do that, there's something we need to understand about appearances.

### ## Appearances may inherit from a base class

When working with an appearance, you might notice that it inherits a base class.

For example, taking another look at the Message Box. We can see, if we look at the **Components** pane that it inherits from **window**.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FCYcx79slh3pKoZY4VYIY%2Fimage.png?alt=media&#x26;token=06c11a72-24c9-45b7-9c7f-2060af7f7da4" alt=""><figcaption></figcaption></figure>

This means it will pick up all of **window's** styles/properties by default.

Of course, you can then override those by defining more specific properties.

Where this comes in particularly handy is if you want to create your own items, based on an existing component.

### Defining your own, brand new styles

Let's say you want to create an entirely new kind of button.

So not just a different state for the existing button, but a new type of button you can use when you want to have a completely different appearance.

You can add a new appearance to the existing appearances, by clicking the + icon in the **Components** pane.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FUMrJonpL9VFa9wZELGFR%2Fimage.png?alt=media&#x26;token=91d7ac84-27d1-4321-9154-7934f2b54db8" alt=""><figcaption></figcaption></figure>

In this case, we want our appearance to look like a button.

So we can set it's `inherit` property to `button.`

Now it will look the same as the existing `button` appearance, except for the styles/properties we override.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FyEWPJvaqRBhKN8FQiX3u%2Fimage.png?alt=media&#x26;token=a441be80-cac8-467a-97a6-21d45c544d1c" alt=""><figcaption></figcaption></figure>

In this case I've overridden the `backgroundColor` style to give it a bold purple background and the `textColor` property to give it white text.

Heading back to our WiseJ.NET application we can use this new style, by setting the `appearanceKey` for any of our buttons.

<figure><img src="https://3188166459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZg1RIEjJ5H42ECDnFfU%2Fuploads%2FleMc84rYd2n3TufTjSIX%2Fimage.png?alt=media&#x26;token=9d7b647f-5c9b-4599-8f15-d816674b892d" alt=""><figcaption></figcaption></figure>

By setting `appearanceKey` to `myButton` we ensure this button picks up our new **MyButton** appearance.

### In Summary

So there you have it.

You can configure just about any aspect of your Wisej.NET application.

Theme Builder provides a convenient way to see, and tweak the style of any of your Wisej.NET controls.

You can then add the theme to your project and see the results in the designer as you build your components.

Finally, you can specify the theme for your app via config, and/or enable the users to switch theme programmatically as they interact with your application.
