Initialized event never raised on TChart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Christo Zietsman
Newbie
Newbie
Posts: 34
Joined: Thu Sep 04, 2008 12:00 am

Initialized event never raised on TChart

Post by Christo Zietsman » Thu Oct 09, 2008 9:17 am

I've tried to attach to the initialized event in XAML. The event never got fired. I've also tried to attach to the mouse double click event and that also never got fired, but that isn't illustrated in this example.

The XAML:

Code: Select all

<Window x:Class="WPFDemo.Window3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Chart="clr-namespace:Steema.TeeChart.WPF;assembly=TeeChart.WPF"
    Title="Window3" Height="300" Width="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Content="My Chart" Initialized="Label_Initialized"/>
        <Chart:TChart Grid.Row="1" Margin="0,0,0,0" Name="Chart" Initialized="Chart_Initialized"/>
    </Grid>
</Window>
The code behind:

Code: Select all

using System;
using System.Windows;

namespace WPFDemo
{
    /// <summary>
    /// Interaction logic for Window3.xaml
    /// </summary>
    public partial class Window3 : Window
    {
        public Window3()
        {
            InitializeComponent();
        }

        private void Label_Initialized(object sender, EventArgs e)
        {
            MessageBox.Show("Label Initialized.");
        }

        private void Chart_Initialized(object sender, EventArgs e)
        {
            MessageBox.Show("Chart Initialized.");
        }
    }
}

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Re: Initialized event never raised on TChart

Post by Christopher » Thu Oct 09, 2008 2:08 pm

Hello Christo,
Christo Zietsman wrote:I've tried to attach to the initialized event in XAML. The event never got fired. I've also tried to attach to the mouse double click event and that also never got fired, but that isn't illustrated in this example.
Strange. TChart derives from UserControl, so it should work. In fact, I created a very simple UseControl like this:

Code: Select all

namespace MyUserControl
{
  /// <summary>
  /// Interaction logic for UserControl1.xaml
  /// </summary>
  public partial class UserControl1 : UserControl
  {
    public UserControl1()
    {
      InitializeComponent();
    }

    protected override void OnRender(DrawingContext drawingContext)
    {
      Rect rect = new Rect(RenderSize);
      drawingContext.DrawRectangle(Brushes.AliceBlue, new Pen(Brushes.Red, 1), rect);
      base.OnRender(drawingContext);
    }
  }
}
and then used it in the XAML of a standard WPF window like this:

Code: Select all

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="clr-namespace:MyUserControl;assembly=MyUserControl"
    Title="Window1" Height="351" Width="496">
    <Grid>
    <mc:UserControl1 Margin="0,0,0,0" Name="uControl1" Initialized="uControl1_Initialized"/>
  </Grid>
</Window>
with the code behind like this:

Code: Select all

    private void uControl1_Initialized(object sender, EventArgs e)
    {
      MessageBox.Show("Hello!");
    }
this doesn't work either. Maybe this is a WPF bug? Can you reproduce the above at your end?
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Christo Zietsman
Newbie
Newbie
Posts: 34
Joined: Thu Sep 04, 2008 12:00 am

Post by Christo Zietsman » Fri Oct 10, 2008 6:41 am

Hi Christopher,

It didn't work on my side either. Maybe this is a WPF bug as you suggested. UserControl & Label both derive from ContentControl. I spied around using .NET Reflector and there isn't much difference between these two controls, but I'm not an WPF framework expert.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Oct 10, 2008 11:10 am

Hi Christo,

We have done some research on the issue in some forums and so far we have been suggested that, as a workaround, you could try using the Loaded event instead, which is fired after the control is laid out and rendered.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Christo Zietsman
Newbie
Newbie
Posts: 34
Joined: Thu Sep 04, 2008 12:00 am

Post by Christo Zietsman » Fri Oct 10, 2008 11:47 am

Hi Narcís,

Yes that is the solution I came up with too.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Fri Oct 10, 2008 1:19 pm

Hello,
Christo Zietsman wrote:Yes that is the solution I came up with too.
For completeness, you might like to have a look at this MSDN Forum thread.

As there is no way for you to subscribe to the event before the InitializeComponent() method of TChart, then using the Loaded event seems the best option.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Post Reply