MouseOver event are missing alternately - wpf

I'm using a modified form of treeview, for the treeviewitem there is a template to show a textbox with a done button in a popup. I have used a static class to find if the mouseOver
(IInputElement currentPosition = Mouse.DirectlyOver;) event on any of the other treeview item to highlight them other than the one in Popup textbox. Items are added dynamically to this treeview. I'm using MVVM model here.
The problem is that when the first item is added and is in Popup textbox , the mouseover for the entire application is somehow turned off, which is not required. But on adding the second item and leaving it in the Popup textbox, the mouseover is switched on, i.e the treeviewitems get highlighted when mouseover occurs. this happens alternately....
What is capturing this mouseover event..??

try using snoop it can tell you what events are being raised, handled. and its a cool tool as well for the wpf man (or woman:)

Related

How do I find out where the focus is going in my WPF application?

I have a search screen in my WPF application. The screen is implemented as a UserControl in a TabItem of a TabControl. When the user switches to the Search tab, I want the focus to go into one particular field.
So I added a Loaded event handler to the UserControl tag in the Xaml and I called the Focus method of the control I want to have the initial focus in the Loaded event handler. This worked great until I upgraded the Telerik control library I'm using today. Now, when I switch to the Search tab, the focus is NOT in the field I want to have it, but I can't tell what control does have the focus.
The field I want to have focus already has GotFocus & LostFocus event handlers for other reasons. I remembered that in Win Forms, the LostFocus event handler arguments tell you which control is going to get the focus. So I put a breakpoint in my LostFocus handler & discovered that the arguments to the LostFocus event handler in WPF don't include that information.
How can I figure out where the focus is going without putting GotFocus handlers on every control in my UserControl?
Tony
You can try putting your breakpoint on the LostKeyboardFocus Attached Event instead of the LostFocus Event. It uses the KeyboardFocusChangedEventArgs Class which does have properties that show which element had focus and where the focus is going.
private void textBox1_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
textBox1.Text = ((FrameworkElement)e.NewFocus).Name ;
}
Try to press Tab Key and see if it helps you find the control in focus.
You can also use Snoop as suggested in this Q/A: Any tips on debugging focus issues in WPF?
For starters, Snoop shows the current focused element and the current
FocusScope in the status bar.
You can get it to show you all the GotFocus and LostFocus events:
1. Run your app.
2. Run Snoop.
3. Choose your app in the dropdown.
4. Click the binoculars ("Snoop") button.
5. On the right pane, click the Events tab.
6. Click to bring down the dropdown.
7. Scroll down to the Keyboard section and check GotKeyboardFocus, LostKeyboardFocus, and optionally the PreviewXXX events.
8. Now do what you need to do to manipulate focus and watch the Snoop window.
Similarly you can track the FocusManager events the same way.

wpf selecting controls inside a listbox

I have a textbox and some labels inside the data template of bounded listbox.
When I click on any label the whole item is highlighted in blue, but when I click directly on a different textbox the selection does not change.
Is there a way to make the selection of the listbox change even when a textbox is clicked?
thanks
This is what I've exactly asked few days ago, see post: "WPF: Trigger SelectedIndex changed whilst clicking on any control within a ListBoxItem area"
basically there are few solutions, using code behind and XAML, but I've not verified latter approach yet
The reason is because the TextBox handles the click event in order to receive focus. There are a number of ways to handle this, including but not limited to:
stop the TextBox handling mouse events (which prevents the user from focussing it using the mouse)
use an eventhandler when the TextBox gains focus (or PreviewClick or similar), to select the parent ListItem

WPF popup on ListBoxItem

I have a MiniToolbar popup that shows up at Mouseover on a ListBoxItem, it needs to show just under the item.
(a MouseOver trigger also sets the IsSelected property on the items)
I tried two options :
define the popup on the items DataTemplate
define the popup on the ControlTemplate for the ListBoxItem
Both options work fine, however I was wondering if the popup was recreated each time ??
(please advise)
I think it would be better to define the popup in the ControlTemplate of the containing ListBox rather than the ListBoxItem ?
I tried this, but could not find the binding expression for placement property relative to the SelectedItem (it shows up at the bottom of the ListBox, not bottom of ListBoxItem).
Any suggestions ?
thanks in advance.
Michael.
The popup is created one time for each list box item in both cases.
I would not suggest that you use single popup for all items in the CotnrolTemplate for the list box because it significantly complicates things. But if you still want to do so, you can set Placement="Custom" on you popup and specify CustomPopupPlacementCallback. In that callback you can calculate the placement using the position of currently selected item.

Programmatically setting a templated Button's VisualStates

In my WP7 application, I have a ListBox populated with buttons. I have a 'Pressed' visual state configured, and it works great. However, I would like to disable that 'Pressed' visual state (temporarily set it to do nothing) while the ListBox is scrolling.
I've created an event handler for detecting when the ListBox is scrolling (using Peter Torr's blog entry here. Using that event handler, how can I alter/disable that 'Pressed' visual state, and also return it to its originally (through XAML) defined state? The ListBox 'Generated Items' template is the button control, which itself is templated to use my custom 'Pressed' state animation.
Thanks!
This is not execly what are you looking for, but you can try setting
myButton.IsEnabled = false;
I assume your goal is to prevent user from clicking a button while scrolling.

Doubleclicking tab control header

I've been wondering about this problem for some time - doubleclicking a winforms TabControl's header doesn't get detected, but I'd like to handle this event.
It looks like all mouse events (click,move,etc.) don't get raised when they are on the 'inactive' area of TabControl. I've even tried subclassing TabControl, but the derived class' events aren't raised too. Overriding WndProc shown that it doesn't receive WM_LBUTTONDBLCLK message (I mean - WTF?).
Thanks.
But I'm sure that the tab control knows that I've clicked on its header, it just doesn't let me know.
p.s. I've looked at .NET : Double-click event in TabControl - but nothing
Hm...I did a test project and I am getting both MouseDoubleClick and DoubleClick events. What do you mean by "Tabcontrol's header"? An actual tab or the blank area were additional tabs would show?
I used eventspy.zip
If you mean the blank area (which you do by the comment) then no, because there is nothing in the blank area. No control. What you need to do is put the TabControl in a Panel, and set the TabControl's Dock property to Fill. Handle the Panel's double-click events.

Resources