2017-04-10 63 views
2

綁定的多個DataSeries的自定義RolloverModifierLabel在我更新到SciChart的最新版本之前,我已經有了這個自定義滾動修改器,可以爲我「滾動」的任何給定點顯示多個值。 它實現這樣的:SciChart:爲代碼

<sci:RolloverModifier 
    DrawVerticalLine="True" 
    ShowTooltipOn="Always" 
    SourceMode="AllVisibleSeries" 
    TooltipLabelTemplate="{StaticResource RolloverLabelTemplate}" /> 

RolloverLabelTemplate是一個控件模板:

<ControlTemplate 
    x:Key="RolloverLabelTemplate" 
    TargetType="sci:TemplatableControl"> 
    <Grid> 
    ... 

現在RolloverModifier.TooltipLabelTemplate從API消失了,似乎被TooltipTemplate,這需要一個DataTemplate,不可替代一個ControlTemplate。我試圖使類似的DataTemplate:

<DataTemplate 
x:Key="SomeTemplate" 
DataType="s:XySeriesInfo"> 
<Grid> 

但是當我嘗試把它分配給RolloverModifier,

<s:RolloverModifier 
    ... 
    TooltipTemplate="{StaticResource SomeTemplate}" /> 

我得到以下異常:

無法投類型的對象 'SciChart.Charting.ChartModifiers.RolloverModifier'鍵入 'SciChart.Charting.Visuals.RenderableSeries.BaseRenderableSeries'。

我試圖按照此文件:https://www.scichart.com/documentation/v4.x/webframe.html#RolloverModifier.html

和造型的工具提示模板的話題,它表明有RolloverModifier,但對TooltipTemplate添加到RenderableSeries:

<s:SciChartSurface.RenderableSeries> 
     <s:FastLineRenderableSeries s:RolloverModifier.TooltipTemplate="{StaticResource XyTooltipTemplate}"/>        
    </s:SciChartSurface.RenderableSeries>   

    <s:SciChartSurface.ChartModifier> 
     <s:ModifierGroup> 
     <s:RolloverModifier ShowTooltipOn="Always" />     
     </s:ModifierGroup> 
    </s:SciChartSurface.ChartModifier> 
</s:SciChartSurface> 

這對我來說是個問題,因爲我沒有在xaml中定義的RenderableSeries。他們被綁定到視圖模型:

<sciVisuals:SciChartSurface 
    ... 
    SeriesSource="{Binding SciSeries}"> 

會有多個,其實我甚至不知道有多少。我如何在這種情況下自定義翻轉工具提示標籤?

回答

1

在SciChart WPF v4.x或更高版本中,有必要將TooltipTemplate應用於該系列,因爲許多用戶要求能夠單獨對樣式進行樣式設置。例如燭臺系列應該有一個不同的工具提示,而不是一個系列。

請參閱SciChart WPF Documentation for applying a RolloverModifier TooltipTemplate在V4 +:

樣式化工具提示項模板

SciChart默認有許多都有它獨特的串聯式工具提示模板。
要更改工具提示模板,使用RolloverModifier.TooltipTemplate附加屬性:

<s:SciChartSurface > 
    <s:SciChartSurface.Resources> 
     <!-- Tooltip Template for an XyDataSeries binds to XySeriesInfo --> 
     <!-- Check out the properties on XySeriesInfo to see what you can bind to --> 
     <DataTemplate x:Key="XyTooltipTemplate" DataType="s:XySeriesInfo"> 
     <StackPanel Orientation="Vertical">    
      <TextBlock Foreground="White"> 
       <Run Text="Series: "/> 
       <Run Text="{Binding SeriesName, StringFormat='{}{0}:'}"/> 
      </TextBlock>    
      <TextBlock Foreground="White"> 
       <Run Text="X-Value: "/> 
       <Run Text="{Binding FormattedXValue}"/> 
      </TextBlock> 
      <TextBlock Foreground="White"> 
       <Run Text="Y-Value: "/> 
       <Run Text="{Binding FormattedYValue}"/> 
      </TextBlock> 
     </StackPanel> 
     </DataTemplate> 
    </s:SciChartSurface.Resources> 
    <s:SciChartSurface.RenderableSeries> 
     <s:FastLineRenderableSeries s:RolloverModifier.TooltipTemplate="{StaticResource XyTooltipTemplate}"/>        
    </s:SciChartSurface.RenderableSeries>   
    <s:SciChartSurface.ChartModifier> 
     <s:ModifierGroup> 
     <s:RolloverModifier ShowTooltipOn="Always" />     
     </s:ModifierGroup> 
    </s:SciChartSurface.ChartModifier> 
</s:SciChartSurface> 

我的建議,以便儘管使用MVVM API的風格,這些是XAML來創建你的風格和使用SeriesBinding MVVM API應用它們。

SciChart WPF文檔中有關於how to style a tooltip when using the MVVM API here的常見問題解答。

很多客戶問我們如何在MVVM API中使用SciChart中使用的各種附加屬性。例如,給定的以下附加屬性,我們如何將其轉換爲MVVM API?

解決方案很簡單,使用我們的Worked Example - Style a Series in MVVM中呈現的RenderableSeries的樣式設計方法。

只需在View中聲明附件中的屬性和工具提示模板。

現在,使用BaseRenderableSeriesViewModel.StyleKey屬性應用樣式。 SciChart將會採用這種風格,並完成其餘的工作。

如果你還在使用舊的,SeriesSource API(注意,這是現在已經過時的4.x版的),那麼我建議你申報風格XAML和使用this technique to access a style in code-behind應用它。

+2

你先生,是個紳士和學者。 – Shaggydog

+0

有用的信息,但你可以做一些類似的工具提示創建一個DataTemplate(如TooltipTemplate可以讓你做)? – colmde

+0

不,在SciChart v4中,工具提示被移到了系列中,因爲它解決了每個系列工具提示的需求。例如,燭臺系列需要與線條系列不同的模板。如果需要,可以使用WPF的隱式樣式功能將全部模板應用於所有系列:https://wpf.2000things.com/tag/implicit-style/ 創建樣式,TargetType = BaseRenderableSeries,no x:Key ,並將此樣式包含在SciChartSurface.Resources中。試試吧:) –