Я пытаюсь привязать свойство Title оси Live Charts к локальному свойству. Я создал UserControl следующим образом:
<UserControl x:Class="LiveChartCustom.LUTgraph"
x:Name="ucLUTgraph"
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:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:LiveChartCustom"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<lvc:CartesianChart x:Name="diagram" LegendLocation="Top" Series="{Binding ElementName=ucLUTgraph, Path=Series}">
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="{Binding ElementName=ucLUTgraph, Path=XLabel}" />
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<TextBox HorizontalAlignment="Left" Height="23" Margin="344,328,0,0" TextWrapping="Wrap" Text="{Binding ElementName=ucLUTgraph, Path=XLabel}" VerticalAlignment="Top" Width="120"/>
</Grid>
</UserControl>
Код содержит свойство зависимости для XLabel:
public string XLabel
{
get => (string)GetValue(XLabelProperty);
set => SetValue(XLabelProperty, value);
}
public static readonly DependencyProperty XLabelProperty = DependencyProperty.Register(nameof(XLabel), typeof(string), typeof(LUTgraph));
В главном окне я просто использую элемент управления следующим образом:
<Grid>
<local:LUTgraph x:Name="LUT1" Series="{Binding SeriesCollection}" XLabel="{Binding XLabel}"/>
</Grid>
Код содержит это свойство:
public string XLabel { get => "myXLabel"; }
, а также
this.DataContext = this;
Кстати, я не , устанавливающий DataContext для UserControl где угодно явно.
Проблема в том, что привязка заголовка оси игнорируется, но точно такая же привязка прекрасно работает для TextBox. Привязка для серии также работает так же, как и ожидалось.
Почему не работает привязка для заголовка оси?