I'm trying to use python.net and WPF to have a modern look & feel on my app.
I also want to use the FluentWPF library to give it the MS Fluent style.
I built the FluentWPF project and loaded the dll in python.net and built a simple window XAML to load :
import os
import clr
# add WPF ref, load FluentWPF dll
clr.AddReference("wpf\PresentationFramework")
dll = os.path.join(os.getcwd(), r"FluentWPF-master\FluentWPF\bin\Debug\net45\FluentWPF.dll")
clr.AddReference(dll)
from SourceChord.FluentWPF import *
from System import Exception
from System.IO import *
from System.Windows.Markup import XamlReader, ParserContext
from System.Windows import *
from System.Threading import Thread, ThreadStart, ApartmentState
from System.Windows.Controls import *
class MyWindow(Window):
def __init__(self):
try:
stream = StreamReader("window.xaml")
ctx = ParserContext()
ctx.XmlnsDictionary.Add("fw", "clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF")
self.window = XamlReader.Load(stream.BaseStream, ctx)
Application().Run(self.window)
except Exception as e:
print(e.Message)
# start app
thread = Thread(ThreadStart(MyWindow))
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
The Window XAML :
<fw:Window x:Class="Window"
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:fw="clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="AcrylicWindow"
Width="300"
Height="300"
mc:Ignorable="d">
<Grid Background="#70FFFFFF">
<TextBlock Margin="10"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text="This is AcrylicWindow"
TextWrapping="Wrap" />
</Grid>
</fw:Window>
This is what I have so far, but when I run this code I get the error :
'Cannot create unknown type '{clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF}Window'.' Line number '1' and line position '2'.
I tried to fix it by adding these lignes to the Window ctor thinking it would replace the missing App.xaml used in the library samples :
ctx = ParserContext()
ctx.XmlnsDictionary.Add("fw", "clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF")
Also in the App.xml there is this line :
<ResourceDictionary Source="pack://application:,,,/FluentWPF;component/Styles/Controls.xaml" />
Is this something I can also inject through the ParserContext ? Or I am missing somethig ? I'm not really familiar with WPF yet.