MMCCPaulEden Posted March 11, 2010 Report Share Posted March 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
JuanC Posted March 17, 2010 Report Share Posted March 17, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.