in

Software FX Community

Discuss and find help for all Software FX products.

Reacting to Collapsable Legend Events

Last post 03-17-2010 8:28 PM by JuanC. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-11-2010 6:00 AM

    Reacting to Collapsable Legend Events

    Hi

     

    We are using the following style, supplied by ChartFX, to make the Legend box collapsable:

    <Style TargetType="{x:Type ItemsControl}" x:Key="LegendBoxStyle">
    <Style.Setters>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type ItemsControl}">
    <Expander x:Name="expLegend" Header="Legend Box" Foreground="White">
    <ScrollViewer HorizontalScrollBarVisibility="Auto" MaxWidth="300" Margin="0,5,0,0">
    <ItemsPresenter />
    </ScrollViewer>
    </Expander>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style.Setters>
    </Style>

    Can you advise how we might catch events thrown by the "expExpander" control?

    I had tried Inheriting the ChartFX Chart object and overriding the OnTemplateApplied method but without result:

     

    public class CustomCFXChart : Chart

    {

    public CustomCFXChart ()

    {

     

    }

    public bool LegendExpanded { get; set; }public override void OnApplyTemplate()

    {

    DependencyObject d = GetTemplateChild("expLegend");

    if (d != null)

    {

    (d
    as Expander).Expanded += new RoutedEventHandler(expLegend_Expanded);(d as Expander).Collapsed += new RoutedEventHandler(expLegend_Collapsed);

    }

    base.OnApplyTemplate();

    }

    void expLegend_Expanded(object sender, RoutedEventArgs e)

    {

    LegendExpanded =
    true;

    }

    void expLegend_Collapsed(object sender, RoutedEventArgs e)

    {

    LegendExpanded =
    false;

    }

    }

     

     

    Many thanks

     

     

    Paul Eden

  • 03-17-2010 8:28 PM In reply to

    • JuanC
    • Top 10 Contributor
    • Joined on 03-02-2007

    Re: Reacting to Collapsable Legend Events

    Overwriting OnApplyTemplate will probably not work because we build out our visual tree from many different parts where one of them is the legend box. A simple but not very elegant solution would be to include the style "in-place" in your xaml instead of using it as a resource, e.g.

    <cfx:Chart Gallery="Bar" x:Name="chart1">
      <cfx:Chart.Series>
        <cfx:SeriesAttributes/>
        <cfx:SeriesAttributes/>
      </cfx:Chart.Series>
      <cfx:Chart.LegendBox>
        <cfx:LegendBox>
          <cfx:LegendBox.ContainerStyle>
            <Style TargetType="{x:Type ItemsControl}">
              <Style.Setters>
                <Setter Property="Template">
                  <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ItemsControl}">
                      <Expander x:Name="expLegend" Header="Legend Box" Foreground="White" Expanded="OnLegendExpanded">

    By placing the style directly in your window/page xaml you will be able to hook to the OnLegendExpanded function in your class. We will research alternative options to accomplish this.

    JuanC

Page 1 of 1 (2 items)
Copyright 2008 Software FX, Inc.