473,545 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
+ 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/WPFDiagramDesig ner_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 NewDesignerItem Event 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 NewDesignerItem Event =
EventManager.Re gisterRoutedEve nt("NewDesigner Item",
RoutingStrategy .Bubble,
typeof(RoutedEv entHandler),
typeof(Designer Item));

public event RoutedEventHand ler NewDesignerItem
{
add { AddHandler(NewD esignerItemEven t, value); }
remove { RemoveHandler(N ewDesignerItemE vent, value); }
}

/// <summary>
/// Fires the NewDesignerItem Event with a reference to this instance
/// of the DesignerItem class
/// </summary>
private void NotifyNewDesign erItem()
{
RoutedEventArgs e = new
RoutedEventArgs (DesignerItem.N ewDesignerItemE vent, this);
RaiseEvent(e);
}

</code>

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

<code>
<s:DesignerCanv as
Focusable="true "
x:Name="MyDesig ner"

s:DesignerItem. NewDesignerItem ="MyDesigner_Ne wDesignerItem"
Background="{St aticResource
WindowBackgroun dBrush}"
Margin="10" FocusVisualStyl e="{x:Null}"
ContextMenu="{S taticResource
DesignerCanvasC ontextMenu}"/>

</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.Re gisterClassHand ler() 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.Clic k event and trapping that. This implementation works fine and
my EventHandler is called as expected for all buttons contained in my
DesignerCanvas.

<code>

<s:DesignerCanv as
Focusable="true "
x:Name="MyDesig ner"
ButtonBase.Clic k="MyDesignerBu tton_Click"
Background="{St aticResource
WindowBackgroun dBrush}"
Margin="10" FocusVisualStyl e="{x:Null}"
ContextMenu="{S taticResource
DesignerCanvasC ontextMenu}">
</s:DesignerCanva s>

</code>
Thanks in advance!

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


Oct 1 '08 #1
0 1342

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

Similar topics

12
10637
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. When I modified the file I also stopped and restarted the web server. Can anyone give me some ideas as to why it is not firing? Thanks
3
1490
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
1203
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 OnSetCursor and OnLButtonDown events for the parent window object within the C++ class. Can I do this? My alternative is to define methods within the C++ class...
0
1677
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. When the login is successful login page writes back javascript
7
4565
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 data was actually being edited. I am using bound textbox controls on the form. Could that have anything to do with it? Does anyone know how to...
5
1822
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 Sub Not Firing the Enter Key event except Other Keys.
1
1518
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 to be firing either for each control that is loaded or it just seems to be firing off more then it should on a the page load.
2
3029
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 thing. I'd just want to add a custom routed event with parameters to a user control with VB. I'd like also add common dotnet event style wrapper to...
3
5308
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 C# using WPF. I based the visual representation off a tutorial from CodeProject (http://www.codeproject.com/KB/WPF/WPFDiagramDesigner_Part4.aspx). ...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7921
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7771
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.