Skip to content

Quick start

Simnico99 edited this page Jan 9, 2024 · 13 revisions

Here is a really quick start to get you ready for using the new Mica material in your WPF app.

  1. To start Change the <Window><Window/> for <mica:MicaWindow></mica:MicaWindow>.
  2. Add the namespace by adding xmlns:mica="clr-namespace:MicaWPF.Controls;assembly=MicaWPF".

Here is an exemple:

<mica:MicaWindow  
        x:Class="MicaWPF.DesktopApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MicaWPF.DesktopApp"
        mc:Ignorable="d"
        Title="MainWindow" 
        Height="450" 
        Width="800"
        xmlns:mica="clr-namespace:MicaWPF.Controls;assembly=MicaWPF" >
    <Grid>

    </Grid>
</mica:MicaWindow>

You also need to add this ressource to your App.xaml file: (Click here for MicaWPF version 4 and earlier)

<Application
    x:Class="MicaWPF.DesktopApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mica="clr-namespace:MicaWPF.Styles;assembly=MicaWPF"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <mica:ThemeDictionary DesignModeTheme="Dark" Theme="Auto" /> <!-- And Here (You can change to Light, Dark or auto here) -->
                <!-- <mica:ThemeDictionary />  works too-->
		<mica:ControlsDictionary /> <!-- This is mandatory -->
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Now get into your Window code:

  1. Add the namespace using MicaWPF.Controls;.
  2. Change the Window inherited class to MicaWindow.

Here is an exemple of what it might look like using .NET6:

using MicaWPF.Controls;

namespace MicaWPF.DesktopApp;

public partial class MainWindow : MicaWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }
}

Note For .Net6.0, .Net7.0 and .Net8.0

You will need to change your CSPROJ to include the windows build after the netx.0-windows. Here is an exemple using .Net8.0 just change the net8 for net7 or net6 for the other versions.

MicaWPF:

<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <!-- This can be changed with your available Windows SDK build ex: net8.0-windows10.0.22621.0</-->
<TargetPlatformMinVersion>7.0</TargetPlatformMinVersion>

MicaWPF.Lite:

<TargetFramework>net7.0-windows</TargetFramework>

The result on Windows 11:
image

The result on Windows 10:
image