tags:

views:

5

answers:

0

Hi to everyone, this is a problem i am having with a WPF Control, it's like an address bar where the user can pick a directory from a pop up window, that last pop window became filled with sub-directories of the selected one, only in my case the selection happens 2 times, sometimes 3 or 4. how this is happening,I, absolutely, have no idea, that's why I am here.

looking to this GIF image will give an idea about my control and also about the problem. alt text

as you can see, the pop up window contains a list box, an event handler is attached to the Routed Event SelectionChanged, and here is the event handler attached to that event,


  listBox.SelectionChanged += (dependencyObject, e) =>
  {
    var sender = dependencyObject as ListBox;
    if (sender.SelectedItem == null) return;
    var element = sender.SelectedItem as DirectoryElement;
    if (element.IsDirectory)
    {
       this.Root = element;
       this.Elements.Add(element);
       var textBox = this.Template.FindName("PART_EditableTextBox", this) as TextBox;
       if (textBox != null)
       {
          Keyboard.Focus(textBox);
       }
    }
    else
    {
        MessageBox.Show(string.Format("selected Item: '{0}'", element.Name), "Information",
                            MessageBoxButton.OK, MessageBoxImage.Information);
    }
    e.Handled = true; //this line was added in an attempt to solve the issue
  }

I tried to set a break-point in the event handler, but that problem disappear when the break-point is hit, it works correctly.

If anyone can help, it's very much appreciated, thanks in advance for the effort.