Search code examples
c#wpflivecharts

WPF Conflict between two librairies (LiveChart & HandyControl) create a graph offset


Hello to you,

Adding the WPF component library HandyControl to an application with LiveCharts causes a rather strange problem.

The line of the graph is offset from its points. (See screen- here). I imagine this is due to a conflict between the resources of the two libraries. Indeed when I remove the HandyControl theme, it works fine.

I joined a basic project to reproduce the bug.

https://github.com/nathangobinet/Test-LiveChart-with-HandyControl

The code is very basic:

MainWindow.xaml.cs

<Window x:Class="Test_LiveChart_with_HandyControl.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
    xmlns:local="clr-namespace:Test_LiveChart_with_HandyControl"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Grid>
    <lvc:CartesianChart >
        <lvc:CartesianChart.Series>
            <lvc:LineSeries>
                <lvc:LineSeries.Values>
                    50, 10, 30, 20
                </lvc:LineSeries.Values>
            </lvc:LineSeries>
        </lvc:CartesianChart.Series>
    </lvc:CartesianChart>
</Grid>

App.xaml

<Application x:Class="Test_LiveChart_with_HandyControl.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:Test_LiveChart_with_HandyControl"
         xmlns:hc="https://handyorg.github.io/handycontrol"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <hc:Theme Name="HandyTheme"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

After a day trying to find a solution I didn't succeed. So I'm turning to you to see if you have any ideas.


Solution

  • I finally solved the problem by locating the problematic HandyControl resource:

     <Style TargetType="Path">
        <Setter Property="Stretch" Value="Uniform"/>
     </Style>
    

    Adding:

    <Window.Resources>
        <Style TargetType="Path">
            <Setter Property="Stretch" Value="None"/>
        </Style>
    </Window.Resources>
    

    In MainWindow.xaml solved the problem. Hoping that it might be of use to someone.