<div dir="ltr">Hi Germano,<br><br><div>It helps to look at the full exception and stack trace, not just the exception type. In this case you probably got this error "System.InvalidOperationException: The calling thread must be STA, because many UI components require this." which tells you that the main thread you're calling Application.Run from is not an STA thread.</div><div><br></div><div>The following code shows how to create and show a WPF Window.</div><div><br></div><div>Regards,</div><div>Tony</div><div><pre style="color:rgb(0,0,0);font-family:'Courier New';font-size:9pt">// window.xaml</pre><pre style="color:rgb(0,0,0);font-family:'Courier New';font-size:9pt"><span style="font-size:9pt;line-height:1.5"><Window </span></pre><pre style="color:rgb(0,0,0);font-family:'Courier New';font-size:9pt">    xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>"<br>    Title="Test Window"<br>    Height="300"<br>    Width="300" /><br></pre></div><div><br></div><div><pre style="color:rgb(0,0,0);font-family:'Courier New';font-size:9pt"><pre style="font-family:'Courier New';font-size:9pt"><span style="color:#000080;font-weight:bold">import </span><span style="background-color:#e4e4ff">clr</span><br><span style="background-color:#e4e4ff">clr</span>.AddReference(<span style="color:#008080;font-weight:bold">r"wpf\PresentationFramework"</span>)<br><br><span style="color:#000080;font-weight:bold">from </span>System.IO <span style="color:#000080;font-weight:bold">import </span>StreamReader<br><span style="color:#000080;font-weight:bold">from </span>System.Windows.Markup <span style="color:#000080;font-weight:bold">import </span>XamlReader<br><span style="color:#000080;font-weight:bold">from </span>System.Windows <span style="color:#000080;font-weight:bold">import </span>Application, Window<br><span style="color:#000080;font-weight:bold">from </span>System.Threading <span style="color:#000080;font-weight:bold">import </span>Thread, ThreadStart, ApartmentState<br><br><br><span style="color:#000080;font-weight:bold">def </span>app_thread():<br>    stream = StreamReader(<span style="color:#008080;font-weight:bold">"window.xaml"</span>)<br>    window = XamlReader.Load(stream.BaseStream)<br>    Application().Run(window)<br><br>thread = Thread(ThreadStart(app_thread))<br>thread.SetApartmentState(ApartmentState.STA)<br>thread.Start()<br>thread.Join()<br><br></pre><pre style="font-family:'Courier New';font-size:9pt"><br><br></pre></pre></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jun 20, 2015 at 2:34 PM germano carella <<a href="mailto:germanocarella.list@gmail.com">germanocarella.list@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
I'm Germano From Italy.<br>
<br>
I'm trying to write a wpf application using python for .net.<br>
import clr<br>
clr.AddReference("wpf\PresentationFramework.Classic")<br>
clr.AddReference("wpf\PresentationCore")<br>
from System.Windows import Window,Application<br>
<br>
class MyWindow(Window):<br>
  def __init__(self):<br>
   Window.__init__(self)<br>
   self.LoadComponent("page.xaml")<br>
<br>
Application.Run(MyWindow())<br>
<br>
InvalidOperationException!<br>
<br>
There is something I heve to do?<br>
What is wrong?<br>
Thanks!<br>
Germano<br>
_________________________________________________<br>
Python.NET mailing list - <a href="mailto:PythonDotNet@python.org" target="_blank">PythonDotNet@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/pythondotnet" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/pythondotnet</a><br>
</blockquote></div>