0
votes

I am not getting it after quite a research, that how can I implement simple Lostfocus like we use to do in Winforms. In Windows Form Control, we usually have LostFocus which I use when someome press TAB to lose focus or use mouse to select other controls. But it is not the case with WPF. I first use LostFocus, but when i press tab it doesn't fire the event. however when I click using mouse to other control it does get fired properly. So, this doesn't solve my problem.

Second, I try to use LostKeyboardFocus, it does get fired when using TAB key, and on few occassion when I use mouse to select other element, but not when I select menu item from Parent window menu.

Also, I have my control on User Control, that I put in TAB control on parent window. But when I press TAb key it always select the Parent Window Menu instead of TreeView I have in UserControl.

Any suggest is great help. Thanks.

1
Please don't ask two unrelated questions in the same question.Daniel Hilgarth
Related: stackoverflow.com/questions/5850784/… - read to understand why focus isn't a simple concept.Daniel Hilgarth
Not sure why someone put negative to question. I am simply asking a logical explanation of behaviour as I notice form my code, and what is best workaround or solution. Sorry if I am not clear.Sumit Gupta
@Daneil, Sorry for second question, but I don't see it unrelated. Anyways, the question you mention is specific case when the guy has isEdit. It doesn't make sense to me for my case. Which is unconditional and simple. Hope I make sense.Sumit Gupta
The underlying concepts of logical and keyboard focus are the same. I am not saying that your question is a duplicate, but you can benefit from understanding the concepts involved.Daniel Hilgarth

1 Answers

0
votes

Well, my quest for finding logically reasoning is still not satisfied, but I get the simple thing done simply. @Daniel, as I said I think the two questions are related, well the answer is indeed related. Maybe you can explain my finding that I am putting as answer here.

I simply set the TabIndex property of my Textbox and other control [TreeView] as 1 and 2, now when I press TAB or select the TreeView item using mouse, i got Lostfocus fired up. and since I have Tab Index set within control, it doesn't select Menu item of parent [it does select it as last now]. So that make Lostfocus the function I should use for my purpose.

Anyone with explanation or better solution is still requested to share it. Thanks.