[英]Binding “BindingList” to DataTemplate with converter does not update
I have view model BindingList<Wave>
. 我有视图模型BindingList<Wave>
。
here is the model (only one property is shown). 这是模型(仅显示一个属性)。
public class Wave : INotifyPropertyChanged
{
private double _period;
public double Period
{
get { return _period; }
set
{
if (value.Equals(_period)) return;
_period = value;
OnPropertyChanged(nameof(Period));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Below Im trying to bind view model into canvas and draw them with polyline which works but only once. 在林下,我试图将视图模型绑定到画布中,并使用折线绘制它们,但是只能运行一次。
The problem is that when i change the properties the view does not update. 问题是,当我更改属性时,视图不会更新。 (the converter does not fire after first time). (转换器在首次启动后不会触发)。
<ItemsControl ItemsSource="{Binding WaveCollection, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Polyline Points="{Binding Converter={StaticResource PlotterConverter}}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
PlotterConverter
just returns PointCollection
. PlotterConverter
仅返回PointCollection
。 with some formula but its not important here. 有一些公式,但在这里并不重要。
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new PointCollection(GetPoints(value as Wave));
}
您没有使用Binding Mode = TwoWay
。
<Polyline Points="{Binding ., Mode=TwoWay, Converter={StaticResource PlotterConverter}}"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.