Hello,
The CaptureMouse() call doesn't appear to be working for the MouseRightButtonDown event in my Silverlight 4 application. The code below shows the following:
(1) When holding down the left mouse button inside the IE web browser window, and keeping the button down until the mouse is moved outside the web browser window, if you release the left mouse button at this point, the function UserControl_MouseLeftButtonUp will be reached.
(2) When holding down the right mouse button inside the IE web browser window, and keeping the button down until the mouse is moved outside the web browser window, if you release the right mouse button at this point, the function UserControl_MouseRightButtonUp will not be reached.
Why won't UserControl_MouseRightButtonUp be reached?
<UserControl x:Class="sidebar.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:my="clr-namespace:sidebar"
MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
MouseLeftButtonUp="UserControl_MouseLeftButtonUp"
MouseRightButtonDown="UserControl_MouseRightButtonDown"
MouseRightButtonUp="UserControl_MouseRightButtonUp"
>
<Grid x:Name="LayoutRoot" removed="White">
</Grid>
</UserControl>
--------------------------------------------------------------------------------------
using System.Windows.Controls;
using System.Windows.Input;
namespace sidebar
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
CaptureMouse();
}
private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Debug.WriteLine("LeftMouseUp");
}
private void UserControl_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
CaptureMouse();
e.Handled = true;
}
private void UserControl_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Debug.WriteLine("RightMouseUp");
}
}
}