关于如何让数据绑定与复选框一起工作,我见过许多类似的问题,但我看到的所有示例都是用C语言编写的,我似乎无法将其转换为IronPython。我在窗口中定义了一个复选框:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="Test" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<DockPanel>
<CheckBox Name="bindtest" IsChecked="{Binding Path=o1checked, Mode=OneWay}"></CheckBox>
<Button Content="Toggle" Name="Toggle" Padding="5"></Button>
</DockPanel>
</Window>
我希望它的IsChecked值在以下类中切换self.o1checked
时自动更新:
(该ui
对象是一个类,其中加载了xaml作为ui控件的指令。见here)
那么我该怎么做呢?在阅读了数小时的MSDN绑定文档(也都是C语言)之后,我尝试添加以下内容:
import System
myBinding = System.Windows.Data.Binding("o1checked")
myBinding.Source = self
myBinding.Mode = System.Windows.Data.BindingMode.OneWay
ui.win['CheckBox']['bindtest'].SetBinding(System.Windows.Controls.CheckBox.IsCheckedProperty, myBinding)
这不管用,但看起来至少有点道理。我走对了吗?在
属性应使用INotifyPropertyChanged接口。有关如何在IronPython中实现它的示例,请参见我的blog。在
另请注意,.NET或IronPython中有一个Silverlight bug,当字符串以外的内容应传播回viewmodel时,会导致错误。在
相关问题 更多 >
编程相关推荐