WPF Checkbox issue

D

Dave Weeden

Hi everyone,

I've run into a strange problem when prompting the user to confirm whether
they want to clear a checkbox.

It seems that showing a MessageBox during a PreviewMouseLeftButtonDown event
seems to disrupt normal operation of a checkbox in that it will no longer
uncheck itself.

I found a workaround (comment out my hack and see what happens) but am
wondering if this is symptomatic of something bad. Does anyone know?

Thanks,

Dave


Sample XAML
----------------

<Window x:Class="Sample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<CheckBox
PreviewMouseLeftButtonDown="CheckBox_PreviewMouseLeftButtonDown">Click
Me</CheckBox>
</Window>

Associated code
------------------

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Sample
{
public partial class Window1 : Window
{
private const bool SHOW_PROMPT = true;

public Window1()
{
InitializeComponent();
}

private void CheckBox_PreviewMouseLeftButtonDown(object sender,
MouseButtonEventArgs e)
{
CheckBox checkbox = sender as CheckBox;

if (checkbox.IsChecked.GetValueOrDefault() && SHOW_PROMPT)
{
if (MessageBox.Show("Are you sure you want to uncheck me?",
"Prompt", MessageBoxButton.YesNo, MessageBoxImage.Question) ==
MessageBoxResult.Yes)
{
// HACK
checkbox.IsChecked = false;
}
else
{
// handle event
e.Handled = true;
}
}
}
}
}
 
L

Linda Liu[MSFT]

Hi Dave,

I performed a test based on your sample code and did see the problem on my
side.

I am performing reseach on this issue and will get back to you ASAP.

I appreciate your patience!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Linda Liu[MSFT]

Hi Dave,

Since the MessageBox grabs focus, the events that follow
PreviewMouseLeftButtonDown (PreviewMouseLeftButtonUp, then
Checked/Unchecked) are never fired in the Window. The fact is that when the
MessageBox is closed, the tunneling/bubbling events aren't restorted in the
Window. Personally, I don't think it's a bug.

Add traces or breakpoints to handlers for PreviewMouseLeftButtonUp and/or
Checked and Unchecked, with and without the MessageBox to see how they are
and are not fired.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top