Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding checkbox to string in IronPython
    text
    copied!<p>How can I bind a checkbox to a string such that when the checkbox is checked/unchecked, the value of the string changes? I have this (with CheckAll as my checkbox):</p> <pre><code>class MyWindow(Window): def __init__(self): wpf.LoadComponent(self, 'BioApp1.xaml') openDialog = SequenceFileOperations() self.Sequences = openDialog.Open() object = MyObjects(self.Sequences) self.CheckAll.DataContext = object self.IDLabel.DataContext = object class MyObjects(object): def __init__(self, Sequences): self.CurrentSeq = Sequences[0] self.ID = self.CurrentSeq.ID </code></pre> <p>and </p> <pre><code>&lt;Label Height="28" HorizontalAlignment="Left" Margin="152,221,0,0" VerticalAlignment="Top" Width="98" Name="IDLabel" Content="{Binding Path=ID}"/&gt; </code></pre> <p>I want that when the checkbox is unchecked, the label should display the sequence ID, but when it is checked, it should simply display “All”. For this I need to change the ID property of CurrentSeq to “All”. How do I do that by data binding? Is there any other way I can do this? </p> <p>EDIT: I feel really stupid but I just can’t get this to work. I have been trying to follow the suggestion about using getter/setter but I guess I don’t know enough. Before doing anything more complicated, I simply want to make a button disabled when I tick the checkbox and enable it when I uncheck it. This is what I wrote:</p> <pre><code>class MyWindow(Window): def __init__(self): wpf.LoadComponent(self, 'App1.xaml') object = BindingClass(self.Check, self.PreviousBtn) self.PreviousBtn.DataContext = object class BindingClass(object): def __init__(self, Check, PreviousBtn): self.Check = Check self.PreviousBtn = PreviousBtn def GetEnabledConverter(self): if self.CheckAll.IsChecked: return self.PreviousBtn.IsEnabled def SetEnabledConverter(self): if self.CheckAll.IsChecked: self.PreviousBtn.IsEnabled = False else: self.PreviousBtn.IsEnabled = True EnabledConverter = property(GetEnabledConverter, SetEnabledConverter) </code></pre> <p>And:</p> <pre><code>&lt;Button Content="Previous" IsEnabled="{Binding Path=EnabledConverter}" /&gt; </code></pre> <p>Unfortunately there is no error but no effect either. The code does not do anything. Would really appreciate if you could help me out with this.</p> <p>EDIT2: Using the notify_property, I tried this:</p> <pre><code>class MyWindow(Window): def __init__(self): wpf.LoadComponent(self, 'Test.xaml') c = Converters(self.check1, self.Button) self.Button.DataContext = c class Converters(NotifyPropertyChangedBase): def __init__(self, check, button): super(Converters, self).__init__() self.Check = check self.Button = button @notify_property def ButtonEnabled(self): return self.Button.IsEnabled @ButtonEnabled.setter def ButtonEnabled(self): if self.Check.IsChecked: self.Button.IsEnabled = False else: self.Button.IsEnabled = True </code></pre> <p>Still the same result: no effect. I just cannot understand where the problem is.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload