Benglin/Dynamo — pull request #68 by aosyatnik (2014-09-19 13:48:50+00:00)
Title: DUI: Sometimes ClassButton is not highlighted, but the list is presented

# Bug
[MAGN-4689](http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-4689) DUI: Sometimes the math list is not highlighted when the list under math is open

![image](https://cloud.githubusercontent.com/assets/8158404/4334416/b05c749c-3fee-11e4-9782-2fe791afe3fa.png)
Steps to reproduce:
Choose any 2 buttons, so that one is under another(e.g. Color and Formula)
1. Click Color.
2. Click Formula.
3. Make this several times, at 2nd or 3rd it will be broken.
The same thing occurs sometimes with every item and item directly under it.
Catch this bug during debugging is impossible. If I put breakpoint inside `OnClassViewSelectionChanged` everything will work correctly... allways.
# Reason
The reason is that `sender` in `OnClassViewSelectionChanged` sometimes is wrong.
I don't know why, but it happend only with buttons, when one is directly under another.
# Solution
Let me explain what I could do.
This method
``` c#
private void OnClassButtonCollapse(object sender, System.Windows.Input.MouseButtonEventArgs e)
```
is called every time, when user click on ClassButton. It was used to collapse ClassButton after second click.
We know, that `classButton` is `ListViewItem`. Also we know, that `classButton.Content` is `BrowserInternalElement`. I called it `AssumedItem`.

And this method is called everytime, when SelectedItem is changen.
``` c#
private void OnClassViewSelectionChanged(object sender, SelectionChangedEventArgs e)
```

So, I assume that `AssumedItem`from the 1st method and `(sender as ListView).SelectedItem` from the 2nd are the same things. Actually that is true, but...
Sometimes SelectedItem doesn't equal AssumedItem. Look on it:
![image](https://cloud.githubusercontent.com/assets/8158404/4335964/1ac203d4-4002-11e4-94a3-fdb21fe52383.png)

![image](https://cloud.githubusercontent.com/assets/8158404/4336038/dda3abb4-4002-11e4-8373-e23805aec338.png)

In this example SelectedItem is ClassInformation. It means our selected item is StandardPanel. It seems to be impossible, because StandardPanel is not focusable at all. Magic... But we have, what we have.

# Reviewers
@Benglin,@vmoyseenko, please take a look.

P.S. we need to talk about it with video. I'm sure, it's not so clear.