2010-02-12 8 views
1

Silverlight 3 trousse d'outils est génial. J'utilise BarSeries et silverlight montre la longueur de la barre proportionnelle à la valeur liée. Mais est-il possible d'obtenir la valeur réelle sur la barre ou juste à côté de la barre? Voici mon XAMLSilverlight 3 Toolkit Charting: Comment afficher la valeur sur la barre?

<chartingToolkit:Chart 
         Grid.Column="1" 
         x:Name="chartEnvironmentStatusGlobal" 
         Title="Environment Status"> 
         <chartingToolkit:BarSeries 
          x:Name="chartEnvironmentStatus" 
          Title="Pass" 
          HorizontalAlignment="Stretch" 
          VerticalAlignment="Stretch" 
          Background="Green" 
          IndependentValueBinding="{Binding Path=Instance}" 
          DependentValueBinding="{Binding Path=Count}" 
          AnimationSequence="LastToFirst"> 
          </chartingToolkit:BarSeries> 
         <chartingToolkit:BarSeries 
          x:Name="chartEnvironmentStatus1" 
          Title="Fail" 
          HorizontalAlignment="Stretch" 
          VerticalAlignment="Stretch" 
          Background="Red" 
          IndependentValueBinding="{Binding Path=Instance}" 
          DependentValueBinding="{Binding Path=Count}" 
          AnimationSequence="LastToFirst"> 
          </chartingToolkit:BarSeries> 
        </chartingToolkit:Chart> 

Merci d'avance.

Répondre

2

Vous devrez créer un nouveau modèle pour BarDataPoint. Je ne posterai pas le gabarit entier ici parce que a) il est assez grand et b) je ne suis pas sûr d'où je me trouve sur Copyright.

Vous pouvez obtenir le modèle existant assez facilement si vous avez mélangé vous devriez être capable de créer une copie avec l'outil. Sinon, vous pouvez l'obtenir à partir du code source de son trouvé dans: -

#someSourceCodeRootFolder\Controls.DataVisualization.Toolkit\Charting\DataPoint\BarDataPoint.xaml 

Dans un dictionnaire de ressources créer ceci: -

<Style x:Key="BarDataPointWithContent" TargetType="charting:BarDataPoint"> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <Border ... copy from original template... > 
     <!-- Wads of original VisualStateManager stuff here --> 
     <Grid Background="{TemplateBinding Background}"> 
      <!-- Original set of Rectangles and Border here --> 
      <TextBlock Text="{TemplateBinding FormattedDependentValue}" 
      HorizontalAlignment="Center" /> 
     </Grid> 
     <ToolTipService.ToolTip> 
      <!-- Do something different here perhaps --> 
     </ToolTipService.ToolTip> 
     </Border> 
    </Setter.Value> 
    </Setter> 
</Style> 

En fait ce que je l'ai fait est ajouté cette finale TextBlock et enveloppèrent à la même propriété FormattedDependentValue que l'info-bulle utilise dans ContentControl. Vous pouvez ajouter un style supplémentaire au TextBlock pour obtenir l'apparence souhaitée, vous pouvez également faire quelque chose de différent avec le contenu de l'info-bulle.

Donc, avec ce style traîner, vous pouvez le faire dans le tableau lui-même: -

<chartingToolkit:BarSeries.DataPointStyle> 
    <Style TargetType="BarDataPoint" BasedOn="{StaticResouce BarDataPointWithContent}" > 
    <Setter Property="Background" Value="Red" /> 
    </Style> 
</chartingToolkit:BarSeries.DataPointStyle> 

Note aux MSofties tapi

Pouvez-vous s'il vous plaît ajouter les modèles à la documentation quelque part afin que nous n'avez pas besoin de code source, de Blend ou de Reflector pour les extraire?

+0

A travaillé comme le charme !!! Merci beaucoup. Silverlight templating est génial. – funwithcoding

+0

vous pouvez essayer http://blogs.msdn.com/delay/archive/2008/12/14/expanded-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-updated-for -better-compatibility.aspx pour extraire les templates – Jags