我为 livechart 创建了一个用户控件,并尝试围绕它创建依赖属性。但是依赖属性没有得到更新。我用谷歌搜索并在 StackOverflow 中找到了答案。所以我一直在四处寻找。我按照答案中提到的步骤操作,但仍然无法更新图表。代码:-
<LiveChart:CartesianChart Grid.Row="1" Background="White">
<LiveChart:CartesianChart.AxisX>
<LiveChart:Axis Title="{Binding Path=XAxisTitle, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}" Labels="{Binding Path=XAxisValues, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}"/>
</LiveChart:CartesianChart.AxisX>
<LiveChart:CartesianChart.AxisY>
<LiveChart:Axis Title="{Binding Path=YAxisTitle, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}" LabelFormatter="{Binding Path=Formatter, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}" MinValue="0"></LiveChart:Axis>
</LiveChart:CartesianChart.AxisY>
<LiveChart:CartesianChart.Series>
<LiveChart:LineSeries Values="{Binding Path=SpectrumChartSeries, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"></LiveChart:LineSeries>
</LiveChart:CartesianChart.Series>
</LiveChart:CartesianChart>
我将用户控件命名为 chartControl 并使用了 ElementName。我的后端:-
public List<Point> ChartPoints
{
get { return (List<Point>)GetValue(ChartPointsProperty); }
set { SetValue(ChartPointsProperty, value); }
}
public static readonly DependencyProperty ChartPointsProperty = DependencyProperty.Register("ChartPoints", typeof(List<Point>), typeof(chartcontrol), new FrameworkPropertyMetadata(new List<Point>(), onChartrPointChange));
private static void onChartrPointChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as chartcontrol;
var points = e.NewValue as List<Point>;
control.UpdateChart(points);
}
更改的事件被命中并且值被更新。但仍然没有反映在图表中。所以有点困惑。
问题是当我尝试使用WPF 工具 Snoop并单击线系列时,我可以看到图表立即更新,
点击前:-
点击后:-
慕的地10843
相关分类