У меня есть простое приложение WPF. Вот код WPFКак обновить значение строки WPF DataGrid от IronPython?
<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>
и вот код питона:
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())
Поведение, которое я ожидаю, что на кнопку, нажав, значение в DataGrid следует обновить. Когда я запускаю приложение, запись представляет собой места в столбце со значением 1, но не изменяется при нажатии кнопки. MessageBox подтверждает, что значение обновляется, но DataGrid не видит, что значение обновляется. Где я иду не так?