【发布时间】:2020-10-03 09:10:00
【问题描述】:
我有一个嵌套的 WPF 视图,我通过依赖属性将对象传递到内层。
我的外部 XAML 层将数据传递到 RetentionChartControl.ChartParams:
<local:RetentionChartControl ChartParams="{Binding PeakRow.Chartparams[0], RelativeSource={RelativeSource AncestorType={x:Type local:PeakrowChartGroupControl}}}"></local:RetentionChartControl>
在我的最内层,我有以下 XAML 代码:
<UserControl x:Class="DryLab.Peakmovement.RetentionChartControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DryLab.Peakmovement"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
x:Name="uc"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<lvc:CartesianChart x:Name="cc" Series="{Binding ChartParams.Seriescollection, RelativeSource={RelativeSource AncestorType={x:Type local:RetentionChartControl}}}" >
<lvc:CartesianChart.DataTooltip>
<lvc:DefaultTooltip SelectionMode="OnlySender" />
</lvc:CartesianChart.DataTooltip>
<lvc:CartesianChart.AxisY>
<lvc:Axis Foreground="Black" Title="{Binding ChartParams.TitleAxY, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:RetentionChartControl}} }" LabelFormatter="{Binding ChartParams.Formatter, RelativeSource={RelativeSource AncestorType={x:Type local:RetentionChartControl}}}">
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis Foreground="Black" Title="{Binding ChartParams.TitleAxX, RelativeSource={RelativeSource AncestorType={x:Type local:RetentionChartControl}}}" Labels="{Binding ChartParams.Labels, RelativeSource={RelativeSource AncestorType={x:Type local:RetentionChartControl}} }"></lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
</UserControl>
现在<lvc:Cartesian Chart> 的绑定(来自 LiveCharts https://lvcharts.net/App/examples/v1/wpf/Basic%20Line%20Chart)正在工作,ChartParams 变量已完全评估,我可以访问 Seriescollection。
但是,如果我查看更深的嵌套 <lvc:Axis>(通过 LiveVisualTree),则永远不会评估 Title 属性。
我错过了什么?为什么我不能从 <lvc:Axis> 中绑定到 ChartParams?
感谢任何帮助,如有必要,将发布更多代码。
编辑:
我应该补充一点,当应用程序运行时,我在 Xaml 中触摸我的 Axis.Title,它会重新评估,然后将结果显示为预期的结果
【问题讨论】:
标签: wpf xaml data-binding livecharts