I have view model 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
. 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}}"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.