[IronPython] Referring to Python types in Xaml

Dino Viehland dinov at exchange.microsoft.com
Thu May 17 18:24:37 CEST 2007


We don't generate a type that can be easily consumed from static languages.  Can you use an interface in the DataTemplate line, eg:

  <DataTemplate DataType="{x:Type IFancyData}">

If so then you could declare an interface in C# (or find an existing one which has what you want) and inherit & implement the interface in Python.  Then the interface will be the bridge between the static & dynamic worlds.


-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Bish Bosh
Sent: Thursday, May 17, 2007 8:46 AM
To: users at lists.ironpython.com
Subject: [IronPython] Referring to Python types in Xaml

What is the mechanism for making types in the Python domain available
to the WPF type system for use in a Xaml file?

In the code below I am refering to the Python class to do some
formatting but would have the same problem if I was trying to create
an instance of a Python class in the Xaml file.  Any ideas? I'm pretty
sure I'm missing something simple but fundamental.  As usual.

In Python file I have a type:

  class FancyData(ObservableCollection[str]):
    pass

The collection to be displayed I am adding as an application resource:

   app.Resources.Add('collection', FancyData())

So it can be bound to as expected in the Xaml:

  <ListBox ItemsSource="{Binding Source={StaticResource collection}}"/>

In Xaml file I would like to refer to the type to do some formatting:

  <DataTemplate DataType="{x:Type FancyData}">
    <StackPanel>
       ...

I get the error:

  File data1.py, line 108, in Initialize
  File , line 0, in _stub_##77
  File data1.py, line 26, in LoadXaml
  File , line 0, in _stub_##87
  File PresentationFramework, line unknown, in Load
  File PresentationFramework, line unknown, in XmlTreeBuildDefault
  File PresentationFramework, line unknown, in Parse
  File PresentationFramework, line unknown, in ParseFragment
  File PresentationFramework, line unknown, in _Parse
  File PresentationFramework, line unknown, in ReadXaml
  File PresentationFramework, line unknown, in Read
SystemError: Type reference cannot find public type named 'FancyData'.
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list