Quantcast
Channel: Silverlight Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 801

Commented Issue: ContextMenu of New Window always pops up in Main Window [10170]

$
0
0
In the Silverlight 5 (December 2011 release) the ContextMenu only appears in the Main Window.
Clicking for a ContextMenu from a new Window always pops up the context menu in the main window.
The Silverlight 5 Toolkit's ContextMenu uses a System.Windows.Controls.Primitives.Popup window which defaults to popping up in the main window. Use the Popup.SetWindow method to set the window the Popup should appear in. The ContextMenu class also uses Application.Current.RootVisual to determine the current window.
Use the Window.GetWindow method to determine the Window the popup should appear in.

Creating a new Window in Silverlight 5:

var window = new Window { Title="New Window", Width = 320, Height = 200 };
window.Content = new MyControl();
window.Show();
Comments: ** Comment from web user: ptrelford **

Fixes to ContextMenu class:

Add the following field:

/// <summary>
/// Stores a reference to the current window.
/// </summary>
private Window _window;

Update the right mouse button handler to store the window:

private void HandleOwnerMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
// add these lines
if (e.OriginalSource is DependencyObject)
{
_window = Window.GetWindow(e.OriginalSource as DependencyObject);
_rootVisual = _window.Content;
}
// end
OpenPopup(e.GetPosition(null));
e.Handled = true;
}

Update the OpenPopup method to set the correct window

_popup = new Popup { Child = _overlay };
_popup.SetWindow(_window); // add this line


Viewing all articles
Browse latest Browse all 801

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>