WPF 两个库(LiveChart 和 HandyControl)之间的冲突创建图形偏移
WPF Conflict between two librairies (LiveChart & HandyControl) create a graph offset
你好,
添加 WPF 组件库 HandyControl to an application with LiveCharts 导致一个相当奇怪的问题。
图表的线偏离了它的点。 (参见屏幕 - here)。我想这是由于两个库的资源之间存在冲突。事实上,当我删除 HandyControl 主题时,它工作正常。
我加入了一个基础项目来重现这个bug。
https://github.com/nathangobinet/Test-LiveChart-with-HandyControl
代码非常基础:
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>
经过一天的努力寻找解决方案后,我没有成功。所以我想问问你有没有什么想法。
我终于通过定位有问题的 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中解决了问题。
希望对大家有用。
你好,
添加 WPF 组件库 HandyControl to an application with LiveCharts 导致一个相当奇怪的问题。
图表的线偏离了它的点。 (参见屏幕 - here)。我想这是由于两个库的资源之间存在冲突。事实上,当我删除 HandyControl 主题时,它工作正常。
我加入了一个基础项目来重现这个bug。
https://github.com/nathangobinet/Test-LiveChart-with-HandyControl
代码非常基础:
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>
经过一天的努力寻找解决方案后,我没有成功。所以我想问问你有没有什么想法。
我终于通过定位有问题的 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中解决了问题。 希望对大家有用。