Silverlight: The Power of

The Canvas is usually an underestimated layout control in Silverlight, instead it's really useful and flexible; one the most usefull things I have discovered while playing with Silverlight is to build pages using a Canvas as the most external container and place any other layout control inside it.

Why? it has a very nice and easy support for Z-Indexing and if you diplay some controls/forms/whatever on top of each other is a very simple task to realize. You can easily build a window-like desktop application in this way.

So here's the way in which I usually define my silverlight pages/applications.

Silverlight: How to Add a Context Menù to a FrameworkElement

I want to be able to display a context menù or something else when my mouse is over a series of specified framework element on a given Silverlight Application; keep in mind we do not have support for mouse right click event due to a series of reasons that goes from difficulty of implementation on a cross browser platform to the fact that Mac users generally do not have it.

So we need to think of a little different approach and think of a UI element that can be used to display the menù or whatever we want. The idea I had was to Highlight the control (or framework element) that is under the mouse and display a clickable anchor on the top-right corner of the bounding box surrounding the control.

The anchor can then be clicked to display the menù. The effect I want to obtain is diplayed in the following picture, a blue bounding box surrounding the element and a button to use as anchor.

Extender2

The idea is quite simple, we need an external Canvas that will contain our main page and controls, we will dynamically create a Border and a Button that will be used for the Highlight and for the Anchor, these controls will be added to the canvas and will be resized and repositioned at runtime to fit over the control we have under the mouse. Also we will set the Z-Index of the controls to be greater of the control we want to 'extend', this way they will be displayed on top.

To diplay and remove the highlight we subscribe to the MouseEnter event of the control we want to extend and to the MouseLeave event of the bounding box (Border) used to Highlight the control.

All these function will be wrapped in an Helper class that will be instantiated on the main page, it will also have an AddContextMenu function that will be called for any FrameworkElement we want to extend with a context menu. The class is quite straightforward to implement and doesn't need too many comments, so here it is:

Back to Action!

From time to time I really think that I should start to blog things seriously, but I have to admitt I'm just to lazy to do things properly.

This will be a new start for me and I really hope to carry the whole thing on, so from now on less playing with World of Warcraft and more software developing (maybe).

Due to my 'not so good' english many articles and posts will be subject to continous revisions...cause I really dislike to make mistakes :D.

How to start the debugger for a website in VS2003 after installing IE7

If you get an error trying to start the debugger for a website in VS2003 after the installazion of IE7 caused by the new security settings in the browser, try the following steps maybe they can resolve your problem:

  1. Check that the site is using the 'Integrated Windows Authentication' (in IIS, site properties, Directory Security, Anonymous Access and authentication control).
  2. The user under which runs the site is a member of the 'Debugger Users' group.
  3. Verify that the same user has Full Control access right on the directory in the file system.
  4. Check the we.config to see if the debug flag is setted to true.
  5. In IE7, internet options, Security Tab, under Local Intranet add the site address (usually http://localhost/)
  6. (optional) In IE7, internet options, Security Tab, under Local Intranet, press the Custom Level button and set 'Automatic Logon with current username and password' for the 'User Authentication\Logon' setting.

Related Content