I have a simple WPF application. Here is the WPF code
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WpfApplication3" Height="300" Width="300">
<Grid>
<DataGrid x:Name="dg" Margin="0" Height="149" Width="136">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding value}" ClipboardContentBinding="{x:Null}"/>
</DataGrid.Columns>
</DataGrid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="109,230,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
</Grid>
</Window>
and here is the python code:
import wpf
from System.Windows import Application, Window, MessageBox
from time import sleep
class MyWindow(Window):
def __init__(self):
self.value = Value()
wpf.LoadComponent(self, 'WpfApplication3.xaml')
self.dg.Items.Add(self.value)
def button_Click(self, sender, e):
self.value.increment()
MessageBox.Show(str(self.value.value))
class Value:
def __init__(self):
self.value = 1
def increment(self):
self.value += 1
if __name__ == '__main__':
Application().Run(MyWindow())
The behavior that I expect is that on clicking button, the value in the DataGrid should update. When I launch the application, an entry is places in the column with a value of 1, but it is not updating on the button click. The MessageBox confirms that the value is being updated, but the DataGrid is not seeing that the value is updated. Where am I going wrong?