Can I override the context menu in Silverlight for all browsers that support Silverlight 2.0? - silverlight

It seems like a common question on Google, but I couldn't find a satisfactory answer (unless the answer is 'no')
I would like to add menu items or show a custom menu when a user right-clicks on my Silverlight app.
The closest thing that I found catches the context menu in IE, but not in Firefox, and Chrome shows the context menu and then shows the custom event.
(The tutorial I mentioned was here
http://silverlight.net/blogs/msnow/archive/2008/07/01/tip-of-the-day-14-how-to-right-click-on-a-silverlight-application.aspx)

Here you have an implementation but it's CTRL+Left click, then you get a context menu (about the text, sorry it's in spanish):
http://www.albloguera.es/?p=29
Another option, is the one pointed out do it via javascript, quite chunky solution, and not sure if now it's working in the current 2.0 version :-(.
Good Luck
Braulio

There is no way to do this natively in Silverlight.
I believe that the Telerik control noted elsewhere uses the HtmlBridge to intercept the context click, then draw their own menu, however it does not appear to be working with Silverlight 2.0.40115 now, so maybe Microsoft have closed that gap.
Having no right click is a design decision based on security concerns, rather than a technical one. However I believe that the Microsoft team are considering allowing context menu's in future versions (perhaps even v3)

I've come to the conclusion that it seems it is possible based on my use of Telerik's context menu which works fine on IE, Chrome and Firefox.
Check it out, http://demos.telerik.com/silverlight/#ContextMenu/FirstLook

Related

Parent mnemonics not working when CefSharp browser has focus

Probably a simple question I am sure. So I've created a simple CefSharp browser on a WinForm.
The problem is - when the browser has focus all the menu mnemonics on the parent form are disabled (e.g. "Alt+F" for the file menu, etc)
I have KeyPreview set True on my parent form - is there some setting I need to disable/enable on the browser object to have it pass mnemonics/accelerators/shortcuts up to the parent form?
Turns out - my problem was not related to CefSharp.
I implemented the IKeyboardHandler and that didn't help either. I could see where the handler was reflecting calls back to the parent - but still I didn't get the response to my hotkeys on my menu.
That is when I started looking elsewhere and realized that the Telerik RadMenu I was using on the form did not support Mnemonics. (Off topic: Telerik controls are cool but beware, there are a lot of little bugs like this lurking in them. For the money they charge you wouldn't expect this.)
Solution was to dump Telerik RadMenu and just use a WinForms Menu and problem solved!!

Outdated UI automation tree

I am trying programming an automated tester application using the new native Microsoft UI Automation interface 3.0 (in VC++ 2010, Win7). The Application Under Test (AUT) is a WPF application.
Almost everything works fine... I can install event handlers, navigate through the tree, search elements using various conditions and control the found elements using their patterns.
But yesterday I found a behaviour that leaves me despaired: The UIA tree of my AUT simply is not updated after switching its GUI main panel by clicking one of its main menu buttons.
After clicking the main menu button, I can see the new widgets in the AUT's GUI but the UIA tree still contains the controls that have been there before clicking the main menu button. The (outdated) UIA tree can be still completely read using search functions or using walker but of course it can not be written since the widgets do not exist anymore.
This exactly looks like there would be an outdated cache... however I do NOT use any caching UIA functions at all. None. Never. Nowhere.
I was not able to make the UIA tree update programatically... neither by calling any UIA functions nor by restarting the tester application nor by switching the AUT's GUI back and forth.
This does not happen every time. Sometimes after clicking the main button the tree seems properly up-to-date and everything works fine. However most of the runs it fails.
There is only one (mysterious) way that updates the UIA tree reliably: Using inspect.exe. When using inspect.exe tool for having a brief look into the AUT's UIA sub tree, the problem is suddenly gone and my tester application can access the actual, updated tree immediately! Of course the problem re-appears after restarting the AUT.
What does inspect.exe do to make the UIA tree (of another application!!!) update? How is it possible at all to access gone elements without using any caching? What did I miss?
I really need help.
Ok, some more findings:
UISpy.exe is able to refresh the UIA tree the same mysterious way inspect.exe does (this is especially strange because inspect.exe uses the same native interface as I do but UISpy.exe uses the .NET interface AFAIK). This means this is a kind of system wide and persistent UIA problem and not a pure native-UIA-problem.
The problem does not happend if I do not access the tree before switching the view. I.e. if my tester application does not access the AUT'S view before switching the view by clicking the main menu button, it sees the new widgets without problems. This strongly indicates some caching problem of the native UIA API - even if I have no idea how this could happen because I do not caching at all. Does someone know if there is some internal caching taking place?
I think this could be a API bug. However considering my current experiences with Microsoft Connect I am kind of lost with that showstopper :-(
Someone any idea?
I also tested the Snoop tool. Using Snoop does NOT heal the problem temporarily like Inspect and UISpy do. Regarding Inspect.exe, there is another detail... it is enough to collapse and expands the AUT's sub-tree to temporarily heal the problem.
Ok, update on this. UIA simply seems horribly buggy. I found that reading an element's content array and the length of that array updates the hidden caches. I also had a case where a subtree of a tab was not update but could be updated by switching to another tab and back (reading the content by pattern did NOT help in that case). Both cases were reproducable but I could not find any way to predict or prevent them. Also al lot of third party WPF components seem to be buggy. We finally gave up to use that API.
I know the question is quite old but I figured out what Inspect.exe does to refresh the UIA tree for other applications: look at the Options menu; there's an item labeled SPI_SCREENREADER flag which is checked by default.
Do the following in your code and you will probably get a fresh UIA tree:
SystemParametersInfo( SPI_SETSCREENREADER, TRUE, NULL, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
PostMessage( HWND_BROADCAST, WM_WININICHANGE, SPI_SETSCREENREADER, 0);

WPF: How to make a Google Chrome style GUI in WPF/MVVM?

I bet you guys know Google Chrome browser, yeah it comes from Chromium open-source projects, added some Google specific features.
I found the multi-tab GUI is quite attractive, especially the "drag-and-drop" feature for tabs and windows:
to "pull a tab" out to form a separate window, or
vice versa, to join a tab into a windows (that has a collection of tabs).
This would be quite helpful for designing some multi-process applications to achieve the stability, and a cool user experience, but ... how?
is it possible to do this in WPF?
or even one step more, is it possible to do this in MVVM?
Yeah, technically, everything is possible, but I can't see an easy pattern to do this
for WPF, how to handle such specific "crossing window" mouse interaction?
for MVVM, hmmm, will this be too challenging for MVVM?
cheers
maybe you should have a look at these libs/frameworks:
http://fabtab.codeplex.com/
http://avalondock.codeplex.com/
http://fluidkit.codeplex.com/
Its definitely possible. I've recreated the chrome tab look in the past with MVVM, complete with drag and drop, and I know another guy who created a tabbed application that lets you "pull away" tabs into a new window of its own. I believe it was all one application with multiple windows, so all open windows were part of the same application even if they show up separately in the task bar.
I'm not sure if I have his source code or not, I'd have to go digging for it.

Can I use the WP7 Panorama control outside of WP7?

I need a WPF control that acts like the Panorama control for Windows Phone 7, but I need it for a desktop application.
It will contain a series of panels (or Panorama Items) that the application will be able to slide through horizontally programmatically.
Also, the content inside the panels not currently displayed on the screen will need to be "lazy loaded". In other words, they should be referenced but not loaded or rendered.
Can I somehow adapt the WP7 Panorama control to do this? Or will I have to develop a custom control from scratch to behave similarly to it?
Thank you!
EDIT:
I could probably use a VirtualizingPanel to implement the lazyload behaviour.
MahApps.Metro while still not super mature does allow for the wp7 Panorama control. Demo of how to use a panorama here. I've played with it a little and while its not the most customizable thing out there it gets the job done. Pretty sweet. Also Sacha Barber (Codeproject Demigod) wrote up an article on making your own. Of which I haven't looked at yet but, the guy usually does awesome work. So I'd check that one out as well.
http://blogs.microsoft.co.il/blogs/arielbh/archive/2010/10/21/porting-windows-phone-7-s-panorama-control-to-silverlight-4.aspx gives some clues about how do to this.
It suggests using http://phone.codeplex.com/ as your base and then you can use http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=4b281bde-9b01-4890-b3d4-b3b45ca2c2e4 (Microsoft Surface Manipulations and Inertia Sample for Microsoft Silverlight) to run convert get it to respond to touch.
Seems none exist as far as I can see so far.
This blog has started an attempt at making it, so you could work from there to make your own. Be sure to also check out this page which details the creation of an individual panorama item too.

Running a Silverlight Website

When using silverlight in a browser is there anyway to switch xaml pages? I'm also wondering how to go about using my encryption class I've wrote in c# to validate users in silverlight. Any help would be much appreciate!
If you're using Silverlight 3 Beta then what you're looking for is the Navigation system using the Frame and Page controls. There are lots of tutorials available online for this.
In Silverlight 2 the easiest solution is to replace the RootVisual with a Panel (like Grid or Canvas) and have your own code to switch the child elements (which are usually your own UserControls).
There's a good tutorial available at Flawless Code
We are using Jesse Liberty's method of doing the page switching in SL2. It is explained here. Jesse Liberty SL2 page switching
It also look or feels a lot like how SL3 does it with the Navigation mentioned above.
Caution: If you do this, the back button on the browser will need to be handled - users will exit out of your SL2 app when hitting the back button. SL3 has built in support for handling and responding correctly to the back button.

Resources