[Ironpython-users] problem incorporating namespace into Xaml
jdhardy at gmail.com
Fri Jul 25 10:25:57 CEST 2014
On Fri, Jul 25, 2014 at 12:45 AM, John Trinder <TrinderJohn at dsl.pipex.com>
> I'm new to FePy and after doing a fair bit of studying am embarking on
> transcoding a C# project to FePy. I'm encountering a problem incorporating
> a module that defines a subclass of Canvas and then trying to utilize this
> custom canvas in the Xaml code.
> My skeleton files/modules and contents are as follows:
> *module1.py *import clr
> import System.Windows.Controls as swc
> class CustomCanvas(swc.Canvas):
> def __init__(self):
> Title="WpfApplication1" Height="300" Width="300">
> *<local:CustomCanvas HorizontalAlignment="Left" Height="100"
> Margin="96,90,0,0" VerticalAlignment="Top" Width="100"/>*
> import wpf
> from System.Windows import Application, Window
> class MyWindow(Window):
> def __init__(self):
> wpf.LoadComponent(self, 'WpfApplication1.xaml')
> I've marked in bold where I have incorporated my module/namespace.
> Intellisense says that on the *<local:CustomCanvas .../>* line,
> CustomCanvas 'does not exist in the namespace *"clr-namespace:module1"'*
> I'm guessing that it's not possible to do (yet) what I want to do - which
> is pretty basic.
> Thanks in advance btw for any advice and tips.
I'm no WPF expert, but I'm guessing the issue is that IronPython doesn't
statically build a "real" .NET class, and the namespace and class name
aren't guaranteed to be the same on each run.*
It is possible to manipulate the type generation using __clrtype__ but
it's not well documented. That allows you to control the exact type name
that is used so that other code can look it up using reflection.
I have grand plans for how this will in IronPython, where classes can take
keyword args and there are function attributes to set types:
class CustomCanvas(swc.Canvas, namespace="Foo"):
Then you could use *xmlns:local="clr-namespace:Foo" *and it would work as
expected. That's still a ways out, though - I'd have to implement support
for those keyword args first. :)
* In your case, the backing type name would be something like
"IronPython.Types.System.Windows.Controls.Canvas$1" - and it's the "$1"
that can change on each run.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users