我正在处理一个控件,该控件上有一个LiveChart CartesianChart,还有一个ListBox,可以在其中选择显示的LineSeries。我试图简化 following LiveCharts example
我的xaml如下:
<Window x:Class="xxx.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:local="clr-namespace:xxx"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Title="xxx" Height="460.36" Width="707.883">
<Grid ShowGridLines="True">
<Grid.Resources>
<local:ChannelReverseConverter x:Key="ChannelReverseConverter"></local:ChannelReverseConverter>
</Grid.Resources>
<Grid.RowDefinitions>
<!--Graph-->
<RowDefinition Height="100*" />
<!--EEPROM and misc-->
<RowDefinition Height="20*"/>
<!--Log window-->
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<lvc:CartesianChart Series="{Binding ChartData}" LegendLocation="Right" DisableAnimations="True" Grid.Row="0">
<lvc:CartesianChart.AxisY>
<lvc:Axis IsMerged="True" Title="Data" LabelFormatter="{Binding YFormatter}"/>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" />
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<ListBox Name="ChannelSelect" Grid.Row="1" Background="Beige" ItemsSource="{Binding ChartData, Converter={StaticResource ChannelReverseConverter}}">
</ListBox>
<TextBox Grid.Row="2" Height="Auto" Background="AliceBlue" TextWrapping="Wrap" AcceptsReturn="True" Name="LogBox" VerticalScrollBarVisibility="Auto"/>
</Grid>
当我尝试运行时,出现上述错误。我猜想,在这种情况下,唯一被使用两次的Visual是ChartData(它是SeriesCollection)。 但是我不明白:
答案 0 :(得分:0)
问题不是ChartData(SeriesCollection类型)。可能是ListBox使用不当。添加ItemTemplate似乎可以解决此问题。这样:
<ListBox Name="ChannelSelect" Grid.Row="1" Background="Beige" ItemsSource="{Binding ChartData, Converter={StaticResource ChannelReverseConverter}}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding (lvc:LineSeries.Title)}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>