locked
Events don't fire RRS feed

  • Question

  • Hi I have a UI class (inhertis from StackPanel) where in constructor I have these:

     

    this.MouseLeftButtonDown += new MouseButtonEventHandler (DockPane_MouseLeftButtonDown);
    this.MouseLeftButtonUp += new MouseButtonEventHandler (DockPane_MouseLeftButtonUp);
    this.MouseMove += new MouseEventHandler (DockPane_MouseMove);

    The events above fire ok when I put the code below in xaml, but it don't when I'm adding instance of this class in code behind.

    XAML:

     

    <local:MainContainer Background="Red" LastChildFill="False" Margin="0,0,0,47" x:Name="main">

    <local:DockPane toolkit:DockPanel.Dock="Top" Height="200" Background="DarkBlue" />

    <local:DockPane toolkit:DockPanel.Dock="Bottom" Height="200" Background="Blue" />

    <local:DockPane toolkit:DockPanel.Dock="Left" Width="200" Background="Green" />

    <local:DockPane toolkit:DockPanel.Dock="Left" Width="200" Background="Maroon" />

    </local:

    Code Behind

    private void Button_Click(object sender, RoutedEventArgs e){

    DockPanel dp = new DockPanel();
    dp.Width = 150;
    dp.Background =
    new SolidColorBrush(Colors.Brown);
    dp.SetValue(
    DockPanel.DockProperty, Dock.Left);
    main.Children.Add(dp)
    }

    Please let me know what's wrong.

    thanks

    cheers

    pete

     

     

     

     

    Monday, December 13, 2010 12:03 PM

Answers

  • Hi Pete. Are you sure you got the code snippets correct? Because in the Xaml snippet you're working with a class named "DockPane", whereas in code you work with a class named "DockPanel".

    Monday, December 13, 2010 12:53 PM

All replies

  • Hi Pete. Are you sure you got the code snippets correct? Because in the Xaml snippet you're working with a class named "DockPane", whereas in code you work with a class named "DockPanel".

    Monday, December 13, 2010 12:53 PM
  • Yes, you are right. Such a silly bug :)

     

    thanks!

    Monday, December 13, 2010 2:38 PM