[Python.NET] Working with XAML and WPF
Victor Demydov
drglitch at gmail.com
Sat Mar 19 19:10:57 CET 2011
Hello,
Has anyone been trying to use PythonNET to drive a WPF-based application?
I am hitting a wall at first step - parsing my XAML with XamlReader. It is
failing with a message indicative of bad Xaml, but it is fine (runs in
IronPython).
Google is proving futile after few hours of searching... any help would be
greatly appreciated!
Sample Code:
# Reference the WPF assemblies
import clr
clr.AddReference("PresentationFramework.Classic, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35")
clr.AddReference("PresentationCore, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35")
import System.Windows
Application = System.Windows.Application
from System.Windows.Markup import XamlReader
class XamlLoader(object):
def __init__(self, xmlData):
self.Root = XamlReader.Parse( xmlData )
def __getattr__(self, item):
return self.Root.FindName(item)
print "begin run"
xamldata = """
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WpfApplication3" Height="300" Width="300">
<Grid></Grid>
</Window>
"""
print xamldata
xaml = XamlLoader( xamldata )
my_app = Application()
my_app.Run(xaml.Root)
print "ending run"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20110319/24edf95f/attachment.html>
More information about the PythonDotNet
mailing list