Popup with StaysOpen to false is not closing

I have a telerik grid view and when I right click the header, I'm showing a with a ListBox inside containing the list of columns.

The item template is redefined to show a check box so I can set the column visible or not. I can also drag/drop columns to reorder them.

So here is how I create my Popup:

var view = new ColumnsOrderer.ColumnsOrderer
            {
                DataContext = new ColumnsOrderer.ViewModelColumnsOrderer(Columns)
            };

var codePopup = new Popup
                    {
                        Child = view,
                        MaxHeight = 400,
                        StaysOpen = false,
                        Placement = PlacementMode.Mouse
                    };
codePopup.IsOpen = true;

Now everything seems to work correctly, but it's not. If I set columns visible or hidden and then click outside the popup, it closes correctly.

Though if I drag an item to reorder it, the popup seems to lose focus and then it won't close if I click outside the popup. I have to click back in the list box inside the popup and then it closes by clicking outside.

Here is my drag/drop events:

public ColumnsOrderer()
{
    InitializeComponent();
    InitialiazeListBoxDragDrop();
}

private void InitialiazeListBoxDragDrop()
{
    var itemContainerStyle = new Style(typeof(ListBoxItem));

    itemContainerStyle.Setters.Add(new Setter(AllowDropProperty, true));
    itemContainerStyle.Setters.Add(new EventSetter(PreviewMouseMoveEvent, new MouseEventHandler(OnMouseMove)));
    itemContainerStyle.Setters.Add(new EventSetter(DropEvent, new DragEventHandler(OnDrop)));

    listColumns.ItemContainerStyle = itemContainerStyle;
}

void OnMouseMove(object sender, MouseEventArgs e)
{
    if (e.OriginalSource is CheckBox || e.LeftButton == MouseButtonState.Released)
        return;

    if (sender is ListBoxItem)
    {
        var draggedItem = sender as ListBoxItem;
        draggedItem.IsSelected = true;

        DragDrop.DoDragDrop(draggedItem, draggedItem.DataContext, DragDropEffects.Move);
    }
}

void OnDrop(object sender, DragEventArgs e)
{
    if (!(sender is ListBoxItem))
        return;
}

An interesting thing is that if I remove the OnDrop handler, the problem is not there. I tried many ways to set back the focus to the popup, but it's not working.

Could anyone help me on that?

Answers


How about trying to re-focus your Popup control after the drag and drop operation?

void OnDrop(object sender, DragEventArgs e)
{
    if (!(sender is ListBoxItem))
        return;
    codePopup.Focus();
}

Need Your Help

FBFriendPickerViewController not showing all friends

ios facebook

I'm using FBFriendPickerViewController to display a list of friends to invite in my iOS app.

Set form submit header

html http http-headers

Is there any way to set the HTTP header fields of a HTML form submit request?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.