Jump to content
Software FX Community

Reacting to Collapsable Legend Events


MMCCPaulEden
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...