0

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?

kFieLd
  • 11
  • 1
  • I am having the same exact issue. I have scoured the internet and the LiveCharts web site, but can't seem to find a resolution to this issue... I'm also trying to bind the Labels property of the axis to a dependency property and it is not working either - same issue. Have you been able to resolve this issue? – David Fletcher Mar 09 '20 at 18:22
  • Good to hear that I am not the only one ;-) But unfortunately I have no solution. I have filed a bug here: https://github.com/Live-Charts/Live-Charts/issues/1049 – kFieLd Mar 10 '20 at 19:29

0 Answers0