I'm trying to bind the Title property of an Live Charts axis to a local property. I have created a UserControl like this:
<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>
The code behind contains the dependency property for 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));
In the Mainwindow I simply use the control like this:
<Grid>
<local:LUTgraph x:Name="LUT1" Series="{Binding SeriesCollection}" XLabel="{Binding XLabel}"/>
</Grid>
The code behind contains this property:
public string XLabel { get => "myXLabel"; }
and also
this.DataContext = this;
By the way, I am not setting the DataContext for the UserControl anywhere explicitly.
The problem is that the title binding of the axis is ignored, but the exact same binding works perfectly fine for the TextBox. The binding for the Series also works just as expected.
Why is the binding for the axis title not working?