[Ironpython-users] [Fwd: RE: How do I get access to the objects of this class which is loaded XAML]

Pascal Normandin pascal at travobject.com
Thu May 17 21:01:46 CEST 2012


To enable Data binding you need to set the DataContext property of the
object loaded from xaml

you could do something like this
sr = StreamReader(path)
userCtrl = XamlReader.Load(sr.BaseStream)
Content = userCtrl
userCtrl.DataContext = self

-----Original Message-----
From: ironpython-users-bounces+pascal=travobject.com at python.org
[mailto:ironpython-users-bounces+pascal=travobject.com at python.org] On Behalf
Of sepatan at sibmail.com
Sent: May-17-12 11:43 AM
To: ironpython-users at python.org
Subject: [Ironpython-users] [Fwd: RE: How do I get access to the objects of
this class which is loaded XAML]

Hello,
That is, if the load XAML, as specified below, the Label (Lab1) can be
binding on the CLR type (p.name) is defined in proba.py (do not forget that
the code is the XAML load in proba.py)?

--------------------------- Original Message ---------------------------
Тема:  RE: [Ironpython-users] How do I get access to the objects of this
class which is loaded XAML
От:    "Pascal Normandin" <pascal at travobject.com>
Дата:  Чтв, Май 17, 2012 21:50
Кому:  sepatan at sibmail.com
       ironpython-users at python.org
--------------------------------------------------------------------------

Hello,

I'm not sure about the LoadComponent method but I have used the
XamlReader.Parse(xaml) and it works well for me.

Using something like

sr = StreamReader(path)
userCtrl = XamlReader.Load(sr.BaseStream) Content = userCtrl

Hope that helps;
Pascal

-----Original Message-----
From: ironpython-users-bounces+pascal=travobject.com at python.org
[mailto:ironpython-users-bounces+pascal=travobject.com at python.org] On Behalf
Of sepatan at sibmail.com
Sent: May-17-12 6:40 AM
To: ironpython-users at python.org
Subject: [Ironpython-users] How do I get access to the objects of this class
which is loaded XAML

How do I get access to the objects of this class which is loaded XAML.
Given that the objects are presented to the CLR types?
 What namespace should be specified?
 The text below gives an error.

1) module proba.py:
....................................
import WPF
class MyWindow(Window):
# p - CLR type, has a property name
	global p
	def __init__(self):
		wpf.LoadComponent(self, 'proba.xaml')

	def button1_Click(self, sender, e):
		MessageBox.Show(p.name)
....................................
not the entire text of the program

2) file proba.xaml:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<!-- This part discusses the -->
        xmlns:local="clr-namespace:proba"
<!-- .................. -->
        Title="Window1" Height="300" Width="300">
    <Grid>
        <Button Name="cnop" Click="button1_Click"/>
        <Label Content="{Binding Source={x1:p}, Path=name}" Height="33"
HorizontalAlignment="Left" Margin="20,12,0,0"
VerticalAlignment="Top" Width="244" Name="Lab1"/>
    </Grid>
</Window>

_______________________________________________
Ironpython-users mailing list
Ironpython-users at python.org
http://mail.python.org/mailman/listinfo/ironpython-users



_______________________________________________
Ironpython-users mailing list
Ironpython-users at python.org
http://mail.python.org/mailman/listinfo/ironpython-users



More information about the Ironpython-users mailing list