0

我将 WPF 工具包用于用 C# 编写的 .Net 4.0 应用程序。我有一个包含绑定到字典的列系列的图表。该图表工作正常,但我想在每列下方的文本框中、每列中间或每列顶部显示每列的实际值。我已经搜索了一段时间,但无法找到有关此的任何信息。我为图表和 ColumnSeries 设置了样式,但还没有取得任何进展。有什么建议么?

我的图表 xaml 是:

xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
...
<Page.Resources>
 <Style x:Key="MyChart" TargetType="DVC:Chart">
  <Setter Property="PlotAreaStyle">
   <Setter.Value>
    <Style TargetType="Grid">
     <Setter Property="Background" Value="#FF2D2D30" />
    </Style>
   </Setter.Value>
  </Setter>
 </Style>

 <Style x:Key="NoLegend" TargetType="DV:Legend">
  <Setter Property="Visibility" Value="Hidden" />
  <Setter Property="Width" Value="0" />
 </Style>

 <Style x:Key="ColumnSeriesStyle" TargetType="{x:Type DVC:ColumnSeries}">
  <Setter Property="IsTabStop" Value="False"/>
  <Setter Property="Template">
   <Setter.Value>
    <ControlTemplate TargetType="{x:Type DVC:ColumnSeries}">
     <Canvas x:Name="PlotArea" Visibility="Visible">
      <TextBox Text="{Binding Path=Value.Value}" IsReadOnly="True"/>
     </Canvas>
    </ControlTemplate>
   </Setter.Value>
  </Setter>
 </Style>
</Page.Resources>
...
<DVC:Chart Name="TempChart" Style="{StaticResource MyChart}" LegendStyle="{StaticResource NoLegend}">
 <DVC:Chart.Series>
  <DVC:ColumnSeries IndependentValueBinding="{Binding Path=Value.Value}"
                    DepdendentValueBinding="{Binding Path=Value.Value}"
                    ToolTip="{Binding Path=Value.Value}"
                    Style="{StaticResource ColumnSeriesStyle}">
   <DVC:ColumnSeries.DependentRangeAxis>
    <DVC:LinearAxis x:Name="TempYAxis"
   </DVC:ColumnSeries.DependentRangeAxis>
 </DVC:Chart.Series>
</DVC:Chart>
4

1 回答 1

0

我设法用这个来设置我的 ColumnSeries 的样式:

<Style x:Key="ColumnSeriesStyle" TargetType="{x:Type DVC:ColumnSeries}">
 <Setter Property="IsTabStop" Value="False"/>
 <Setter Property="Template">
  <Setter.Value>
   <ControlTemplate TargetType="{x:Type DVC:ColumnSeries}">
    <Canvas x:Name="PlotArea" Visibility="Visible">
     <!-- Actual Values -->
     <ListBox x:Name="ActualValueListBox" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
              Background="{StaticResource WindowBackground}" Foreground="#FFBB702F" BorderBrush="#FF2D2D30" ItemsSource="{Binding}" >
      <ListBox.ItemTemplate>
       <DataTemplate>
        <TextBox HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" FontSize="12"
                 Foreground="{StaticResource ValueForeground}" Background="{StaticResource ValueBackground}" Width="40"
                 Text="{Binding Path=Value.Value}" />
       </DataTemplate>
      </ListBox.ItemTemplate>
      <ListBox.ItemsPanel>
       <ItemsPanelTemplate>
        <UniformGrid Rows="1" Height="20" 
                     Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DVC:ColumnSeries}}, Path=ActualWidth}"/>
       </ItemsPanelTemplate>
      </ListBox.ItemsPanel>
     </ListBox>
    </Canvas>
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>
于 2013-03-12T18:20:54.803 回答