两个库(LiveChart 和 HandyControl)之间的 WPF 冲突创建图形偏移量



你好,

将WPF组件库HandyControl添加到带有LiveCharts的应用程序中会导致一个相当奇怪的问题。

图中的线从其点偏移。(请参见屏幕-此处(。我想这是由于两个图书馆的资源之间的冲突。事实上,当我删除HandyControl主题时,它工作得很好。

我加入了一个复制bug的基本项目。

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

代码非常基本:

主窗口.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>

应用程序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>

经过一天的努力,我没有找到解决方案。所以我转向你,看看你是否有什么想法。

我最终通过定位有问题的HandyControl资源来解决问题:

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

添加:

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

在MainWindow.xaml中解决了这个问题。希望它对某人有用。

最新更新