Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OxyPlot触发LineSeries颜色更改通知_C#_Wpf_Data Binding_Ivalueconverter_Oxyplot - Fatal编程技术网

C# OxyPlot触发LineSeries颜色更改通知

C# OxyPlot触发LineSeries颜色更改通知,c#,wpf,data-binding,ivalueconverter,oxyplot,C#,Wpf,Data Binding,Ivalueconverter,Oxyplot,我有一个oxyplot和一个带有颜色选择器的列表框,用于选择LineSeries颜色 ColorPicker通过值转换器绑定到LineSeries我无法使用oxyplot默认颜色转换器,因为ColorPicker使用可为空的颜色-s,所以我必须自定义oxyplot.Wpf.OxyColorConverter 颜色绑定在两个方向都起作用:如果我在颜色选择器中更改颜色,首先调用ConvertBack,然后调用Convert函数。已设置LineSeries颜色和ColorPicker颜色。 启动时,我

我有一个oxyplot和一个带有颜色选择器的列表框,用于选择LineSeries颜色

ColorPicker通过值转换器绑定到LineSeries我无法使用oxyplot默认颜色转换器,因为ColorPicker使用可为空的颜色-s,所以我必须自定义oxyplot.Wpf.OxyColorConverter 颜色绑定在两个方向都起作用:如果我在颜色选择器中更改颜色,首先调用ConvertBack,然后调用Convert函数。已设置LineSeries颜色和ColorPicker颜色。 启动时,我将线系列添加到PlotModel。系列请参见下文 然后,在添加第一个数据点之前,调用ColorConverter.Convert函数,其值={a:0,B:1,G:0,R:0}。这会将ColorPicker颜色设置为某种透明,而LineSeries颜色不会更改 我想,问题是,添加到PlotModel.Series的线系列在添加数据点之前没有有效的颜色集

我在Series或LineSeries实例上未找到任何RaisePropertyChanged或类似通知。 我试图调用RaisePropertyChangedPlotModel;在第一个数据点之后-对PlotModel.Series.Color的任何组合都没有帮助 PlotModel.invalidatePlotrue;在每个数据点之后调用,但这不会通知颜色选择器颜色更改。 所以问题是:在启动后,在手动更改颜色选择器之前,如何使颜色选择器使用LineSeries的有效颜色

我希望避免在实例化时手动设置颜色,现在我对PlotModel分配给它们的颜色很满意

OxyPlot和列表框:

<oxy:PlotView Grid.Column="0" Grid.Row="0" x:Name="plot1" Model="{Binding PlotModel}"/>
...
<ListBox Grid.Column="1" Grid.Row="0" ItemsSource="{Binding PlotModel.Series}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding Path=IsVisible}" />
                <xctk:ColorPicker Width="30" ShowDropDownButton="False" SelectedColor="{Binding Path=Color, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged, Converter={StaticResource ColorConverter}}" Opacity="1" ShowRecentColors="True"/>
                <TextBlock Text="{Binding Path=Title}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
以下是如何动态添加新的LineSeries:

LineSeries l = new LineSeries { LineStyle = LineStyle.Solid, Title = title };
PlotModel.Series.Add(l);

修改LineSeries实例化工作:

LineSeries l = new LineSeries { LineStyle = LineStyle.Solid, Title = title, Color = PlotModel.DefaultColors[PlotModel.Series.Count] };

还有别的办法吗?例如,某种颜色属性更改事件?

此答案修复了一个问题,即在手动创建可检查过滤器的图表中,所选线条的颜色不准确,但我需要它来处理一系列线条。在最新的OxyPlot版本中有11种默认颜色,所以使用C模运算符。所以建议:int index=PlotModel.Series.Count==0?0:PlotModel.Series.Count-1%PlotModel.DefaultColors.Count;LineSeries ls=newlineseries{Title=sq,Color=PlotModel.DefaultColors[index]};
LineSeries l = new LineSeries { LineStyle = LineStyle.Solid, Title = title };
PlotModel.Series.Add(l);
LineSeries l = new LineSeries { LineStyle = LineStyle.Solid, Title = title, Color = PlotModel.DefaultColors[PlotModel.Series.Count] };