问题描述
之前写livecharts实现了仪表盘
但是等到项目成员合代码之后就无法运行
报错状态:
System.Collections.Generic.KeyNotFoundException:“The given key ‘LiveCharts.Wpf.AngularSection’ was not present in the dictionary.”
并且xaml的预览图是正常的
代码如下
<Grid >
<lvc:AngularGauge Value="{Binding SOH}" FromValue="0" ToValue="100"
LabelsStep="50" TicksStep="10" Wedge="230" TicksStrokeThickness="0.2"
TicksForeground="Black" Foreground="black"
FontWeight="thin" FontSize="6"
SectionsInnerRadius=".8">
<lvc:AngularGauge.Sections>
<lvc:AngularSection FromValue="{Binding SOH}" ToValue="100" Fill="white"/>
<lvc:AngularSection FromValue="0" ToValue="{Binding SOH}" Fill="#0098FA"/>
</lvc:AngularGauge.Sections>
</lvc:AngularGauge>
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" HorizontalAlignment="Center" >
<TextBlock FontWeight="Light" FontSize="7" HorizontalAlignment="Center" VerticalAlignment="Bottom" >SOH</TextBlock>
<TextBlock FontWeight="Light" FontSize="7" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding SOH}" ></TextBlock>
</StackPanel>
</Grid>
问题所在
其实报错已经很明显了,但是我之前觉得是包的问题所以一筹莫展
经过一次又一次的尝试
发现value值写数据或者是写数字都是可以的
问题就处在tovalue 和fromvalue里面
<lvc:AngularSection FromValue=“{Binding SOH}” ToValue=“100” Fill=“white”/>
<lvc:AngularSection FromValue=“0” ToValue=“{Binding SOH}” Fill=“#0098FA”/>
我尝试将白色进度变成0到100作为底,并且放在了蓝色进度条的上面
因为渲染的时候先渲染上面的代码,如果白色在下面势必会盖住蓝色的进度条
然后只加了蓝色的进度条 从0开始
发现竟然不报错了
问题就处在白色进度条上的fromvalue
正确代码
<Grid >
<lvc:AngularGauge Value="{Binding SOH}" FromValue="0" ToValue="100"
LabelsStep="50" TicksStep="10" Wedge="230" TicksStrokeThickness="0.2"
TicksForeground="Black" Foreground="black"
FontWeight="thin" FontSize="6"
SectionsInnerRadius=".8">
<lvc:AngularGauge.Sections>
<lvc:AngularSection FromValue="0" ToValue="100" Fill="white"/>
<lvc:AngularSection FromValue="0" ToValue="{Binding SOH}" Fill="#0098FA"/>
</lvc:AngularGauge.Sections>
</lvc:AngularGauge>
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" HorizontalAlignment="Center" >
<TextBlock FontWeight="Light" FontSize="7" HorizontalAlignment="Center" VerticalAlignment="Bottom" >SOH</TextBlock>
<TextBlock FontWeight="Light" FontSize="7" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding SOH}" ></TextBlock>
</StackPanel>
</Grid>
```问题解决
![在这里插入图片描述](https://img-blog.csdnimg.cn/9b1b72c22cc745cdbb102b6f18a643c3.png)