Skip to content

Quick start

Simnico99 edited this page Apr 7, 2023 · 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 Theme="Auto" /> <!-- And Here (You can change to Light or Dark here) -->
		<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 .Net5.0 and .Net6.0

You will need to change your CSPROJ to include the windows build after the netx.0-windows Here is an exemple using .Net6.0 just change the 6 for a 5 on .Net5.0

<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>

The result on Windows 11:
image

The result on Windows 10:
image