473,473 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

RoutedEvent from a class not firing

I am developing a diagramming project within C# using WPF. I based the
visual representation off a tutorial from CodeProject <a
href=http://www.codeproject.com/KB/WPF/WPFDiagramDesigner_Part4.aspx">WPF
Diagram Designer</a>. I've added most of the extensions that I need for the
solution but I'm new to WPF and having trouble getting RoutedEvents to work
correctly.

I have a canvas object which has several designerItems on it. The
DesignerItem class has a RoutedEvent called NewDesignerItemEvent which is
fired whenever a new item is created:

<code>
/// <summary>
/// Notify any listeners that a new Designer Item has been created.
/// </summary>
public static readonly RoutedEvent NewDesignerItemEvent =
EventManager.RegisterRoutedEvent("NewDesignerItem" ,
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(DesignerItem));

public event RoutedEventHandler NewDesignerItem
{
add { AddHandler(NewDesignerItemEvent, value); }
remove { RemoveHandler(NewDesignerItemEvent, value); }
}

/// <summary>
/// Fires the NewDesignerItemEvent with a reference to this instance
/// of the DesignerItem class
/// </summary>
private void NotifyNewDesignerItem()
{
RoutedEventArgs e = new
RoutedEventArgs(DesignerItem.NewDesignerItemEvent, this);
RaiseEvent(e);
}

</code>

Within my XAML I have added an EventHandler that should catch all
NewDesignerItem events that are bubbling up:

<code>
<s:DesignerCanvas
Focusable="true"
x:Name="MyDesigner"

s:DesignerItem.NewDesignerItem="MyDesigner_NewDesi gnerItem"
Background="{StaticResource
WindowBackgroundBrush}"
Margin="10" FocusVisualStyle="{x:Null}"
ContextMenu="{StaticResource
DesignerCanvasContextMenu}"/>

</code>

The behavior I am expecting is that whenever the NewDesignerItem event is
fired for a child within the DesignerCanvas object "MyDesigner" that event
will be "bubled up" to my event handler. However, nothing happens! I can
step through the creation of the DesignerItem and verify that my RoutedEvent
is being called but the Handler never gets it.

I was able to get the event handler to fire by using
EventManager.RegisterClassHandler() within my Window constructor.
Unfortunately, this implementation doesn't meet my goals because I will
eventually have dozens of Canvas objects and I only want to handle the event
on the canvas that "owns" the newly added DesignerItem.

I did a sanity test by replacing my NewDesignerItem event with the
ButtonBase.Click event and trapping that. This implementation works fine and
my EventHandler is called as expected for all buttons contained in my
DesignerCanvas.

<code>

<s:DesignerCanvas
Focusable="true"
x:Name="MyDesigner"
ButtonBase.Click="MyDesignerButton_Click"
Background="{StaticResource
WindowBackgroundBrush}"
Margin="10" FocusVisualStyle="{x:Null}"
ContextMenu="{StaticResource
DesignerCanvasContextMenu}">
</s:DesignerCanvas>

</code>
Thanks in advance!

I'm using Visual Studio 2008 Professional with .NET Framework 3.5 SP1


Oct 1 '08 #1
0 1337

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: qaz | last post by:
For some reason my global.asa file is not firing. I have it located in the root of my website (e.g., wwwroot\mywebsite\global.asa) and I have the web site configured as an "application" in IIS. ...
3
by: Robert W. | last post by:
I want to fire an event within the property of a class. Here's an example: private bool _canprint; public bool CanPrint { get { return _canprint; } set
0
by: jbmeeh | last post by:
I am a newbie to C++. I am writing a C++ class to expose the funtionality of CRectTracker to a C# application. I am passing a parent window object to the C++ class and I want to expose the...
0
by: Ram | last post by:
I have a start page for my application default.htm which contains four frames. header.htm login.aspx rightside.htm footer.htm login.aspx conatins username, password fields and login button....
7
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when...
5
by: Datagridtextboxcolumn not firing event | last post by:
"PLEASE HELP, I NEED HELP N O W !!!" AddHandler dgtxtboxcolumn.textbox.KeyDown, AddressOf TextBoxKeyPress Private Sub TextBoxKeyPress(ByVal sender as Object, ByVal e as KeyEventArgs) End...
1
by: thedotnetarchitect | last post by:
Can anyone tell me why my page load event is firing more then once? I have a asp.net 2.0 page with four user controls and it seems that the user controls are loading but the page load event seems...
2
by: Pon | last post by:
Hi everybody, I posted that on the Avalon ng but it seems there is not so much wpf developpers which use VB. Is there more VB developpers which work with WPF ? I'm trying to do a very simple...
3
by: =?Utf-8?B?YXdhaG9v?= | last post by:
Please forgive the re-post. I did not have a no-spam alias defined the first time I tried and that kept this message from appearing in the database. I am developing a diagramming project within...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.