本文介绍了IronPython的&安培; WPF:绑定的复选框的财产器isChecked一类的成员变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了如何获得一个复选框数据绑定工作,但所有的我见过的例子是在C#和我似乎无法使飞跃许多类似的问题将其转换为IronPython的。我曾经在一个正是如此窗口中定义一个复选框:

I've seen many similar questions on how to get data binding working with a checkbox, but all of the examples I've seen are in C# and I can't seem to make the leap to convert it to IronPython. I have a checkbox defined in a window thusly:

<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 在下面的类翻转:

And I want its IsChecked value to automatically update when self.o1checked is toggled in the following class:

class MaikoCu64(object):
    def __init__(self):
        self.o1checked = False
        ui.win['Button']['Toggle'].Click += self.Toggle_OnClick

    def Toggle_OnClick(self, sender, event):
        self.o1checked = not self.o1checked

(即 UI 对象是具有装入其作为UI控件的dictonary的XAML类见的)

(That ui object is a class that has the xaml loaded into it as a dictonary of ui controls. See here)

那么,如何做到这一点?后通过MSDN阅读结合文档(也都在C#中)我试着添加此时间:

So how do I make this happen? After hours of reading through the MSDN binding documentation (also all in C#) I've tried adding this:

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)

它不工作,但现在看来似乎使得至少有一些感觉。我在正确的轨道上吗?

It doesn't work, but it seems like it makes at least some sense. Am I on the right track?

推荐答案

属性应使用INotifyPropertyChanged接口。看到我的一个例子,如何实现它IronPython的。

The property should use INotifyPropertyChanged interface. See my blog for an example how to implement it in IronPython.

另外注意,在.NET或IronPython的Silverlight的导致错误当比任何其他字符串应该被传播回视图模型。

Also note there is a Silverlight bug in .NET or IronPython causing an error when anything else than string should be propagated back into viewmodel.

这篇关于IronPython的&安培; WPF:绑定的复选框的财产器isChecked一类的成员变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:52