Powershell, Mahapps : error Uunknown type '{clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro}MetroWindow'

64 views Asked by At

I've spent many hours, googling and trying, but I'm still spinning around with this error :

Unable to create unknown type '{clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro}MetroWindow'

I'm not sure it's on code side !

Here's my latest ps1 code : (all DLLs are up to date, an it's working fine in VS2022)

Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms, System.Drawing 

[System.Reflection.Assembly]::LoadFrom('C:\_TestAppWpf\Metro2\MahApps.Metro.dll') | out-null
[System.Reflection.Assembly]::LoadFrom('C:\_TestAppWpf\Metro2\ControlzEx.dll') | out-null
[System.Reflection.Assembly]::LoadFrom('C:\_TestAppWpf\Metro2\Microsoft.Xaml.Behaviors.dll') | out-null

function LoadXml ($FileName) {
    
    $XamlLoader = (new-object system.Xml.XmlDocument)
    $XamlLoader.Load($FileName)
    return $XamlLoader
}

$XamlWindow = LoadXml("C:\_TestAppWpf\testgpt.xml")
$Reader = (New-Object System.Xml.XmlNodeReader $XamlWindow)
$Form = [Windows.Markup.XamlReader]::Load($Reader)

$Form.ShowDialog()

Here's my latest xml code :

<Controls:MetroWindow  
        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:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        xmlns:local="clr-namespace:Test"
        
        Title="TOOLBOX" Height="450" Width="800">

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Accent and AppTheme setting -->
            <!-- Red, Green, Blue, Purple, Orange, Lime, Emerald, Teal, Cyan, Cobalt, Indigo, Violet, Pink, Magenta, Crimson, Amber, Yellow, Brown, Olive, Steel, Mauve, Taupe, Sienna -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Yellow.xaml" />
           <!-- BaseLight, BaseDark -->
           <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />1
       </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>


<Grid>
        <Label Name="label" Content="Client" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="95"/>
        <TextBox Name="textBox" HorizontalAlignment="Left" Margin="10,36,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="222"/>
        <Button Name="button" Content="Afficher les connexions" HorizontalAlignment="Left" Margin="10,76,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1.667,0.055" Width="222"/>
        <ListBox Name="listBox" HorizontalAlignment="Left" Height="26" Margin="269,36,0,0" VerticalAlignment="Top" Width="286">
            <ListBoxItem IsSelected="True" DataContext="Item1,Item2"/>
        </ListBox>
        <Controls:SplitButton Name="splitButton" HorizontalAlignment="Left" Margin="42,157,0,0" VerticalAlignment="Top" Width="120"/>
        <Controls:ToggleSwitch Height="60" Header="SSL" Margin="324,183,0,0" VerticalAlignment="Top" Width="135"/>

</Grid>
    

</Controls:MetroWindow>

I also tried to replace

xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"

with

xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
0

There are 0 answers