我被难住了。我有一个包含业务对象的可观察集合。我将它绑定到 ListBox 的 ItemsSource。我正在更新对象的 X 和 Y,并且它在运行时在 UI 中正确显示,因为它绑定了项目的顶部和左侧。但是,这就是问题所在。我还绑定了一些数据以显示在 textblock 文本属性中,并且数据仅显示初始值。无论我更改多少次,它都不会更新文本块文本。
这是 XAML。如果您发现 XAML 有问题,请告诉我。就像我说的那样,X/Y - Top/Left 绑定工作得很好,并且在更改时会更新,绑定到 DisplayData 的 TextBlock 不会。
此外,我的集合中的业务对象确实实现了 INotifyPropertyChanged。
如果仅通过查看 XAML 无法给出答案,我将尝试制作一个小演示来复制这一点。
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="614" Width="674">
<ListBox Name="PlottingBox" Background="White">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=DisplayData}" />
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Template>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Canvas IsItemsHost="True" />
</Border>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Canvas.Left" Value="{Binding Path=PlotX}" />
<Setter Property="Canvas.Top" Value="{Binding Path=PlotY}" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>