【发布时间】:2015-06-23 19:30:35
【问题描述】:
我想连接 wpfcode 和 Ironpython。但我不知道如何使用 xaml 和 py 文件之间的数据绑定。我该怎么办?
XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WpfApplication9" Height="300" Width="300">
<Grid>
<TextBlock Text="{Binding Path=time1()}" HorizontalAlignment="Left" Margin="10,117,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="272"/>
</Grid>
</Window>
铁蟒:
import wpf
import time
from System.Windows import Application, Window
from time import localtime
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, 'test.xaml')
self.TextBlock.Text = time1()
def time1():
now = time.localtime()
setime = "%02d%02d%02d" % (now.tm_hour, now.tm_min, now.tm_sec)
while 1:
cnow = time.localtime()
ntime = "%02d%02d%02d" % (cnow.tm_hour, cnow.tm_min, cnow.tm_sec)
if int(ntime) != int(setime):
realtime = "%02d:%02d:%02d" % (cnow.tm_hour, cnow.tm_min, cnow.tm_sec)
print realtime
setime = ntime
if __name__ == '__main__':
Application().Run(MyWindow())
time1()
【问题讨论】:
-
你看过answers like this或articles like this吗?这一切都暗示使用 INotifyPropertyChanged。
标签: wpf binding ironpython