How to reload focus on form controls (dockPanels) - winforms

I have one Form with four dockPanels
dock_1
dock_2
dock_3
dock_4
I want to focus on specific dockPanel by changing theirs 'tabIndex'. For dockPanel which should be focused I set tabIndex on 0, rest of dockPanels' indexes I increase.
I need control it inside method to be able trigger changes when I need it. I can set it inside constructor and during form first initialization focus can be set correct but it's not what I need.
The problem is that I can't force realod focus on form so when I change tabIndexes nothing happened.
Do you know how to trigger:
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.UpdateFocusedControl()
It should reload focus inside the form but I'm not able to trigger it.
I tried solutions similar to: myForm.Select() but without any results.
Thanks

The TabIndex property is not applicable for dock panels.
Use the DockManager.ActivePanel property to get or set the currently active dock panel:
dockManager1.ActivePanel = dockPanel1;
The active dock panel is the one that has focus or contains a control that has focus.
When the active dock panel is changed the DockManager.ActivePanelChanged event is fired.

Related

XAML Disabling Events on Child Elements when moving Parent

I have an ItemsControl that Contains a few buttons, My Items control is movable, you can move it around by dragging it. the issue is when I click and drag my control to move it, and leave the mouse on top of a button inside the control, it fires the click event of the button which I dont' want/
So While I am moving the control around I want to disable any events on the child buttons, I used IsDisabled = true but that changes the appearance of the buttons too which I dont want.
you can set IsHitTestVisible property of button to false
IsHitTestVisible="False"

How to remove default focus set on combobox in winform

In windows form, I have 5-7 combobox on one 3 tab pages of tab control.
This tab control reside in a group box.
There are other two groupboxes containg other text box and listview controls.
Problem is, When defualt load the form control then focus set on combobox and unable to unselect.
Tried by changing property- causevalidation to false but no output.
Please guide.
Add a line on Page Load to set focus on the control you want to focus.
For Ex:
txtName.Focus();
EDIT
Use this
ActiveControl = yourcontrolNameToWhichYouWantToSetFocus;
You can set the TabIndex of the controls, the lowest index will be the first focused. (TabStop should be true)
I you want to set focus to another combobox you should call Select() method.

Implementation of menu buttons in WPF/MVVM/Prism

I have a Region in the top left of the WPF application which I want to be my global button bar where the user chooses which screen they want to view, and the appropriate content will then be displayed in the main region. THere will also be a sub navigation region in the top right with sub-menu options within that screen, eg if the user clicked "Maintenance" from the main menu, the sub menu would show options for New, Update, Delete, Edit etc.
What I want to have is a way to create a custom menu bar by simply specifying a list of Text button names, and ICommand/Parameter pairs for the action to invoke on button click. The natural way to do this would be have a MenuButtonViewModel class with dependency properties Title, Command and CommandParameter. One more would also be needed, IsSelected, so there is some visual way for the user to see which screen you are currently on, so it needs to behave like a toggle button, but where only one button in the group can be selected at a time. I can then have a UserControl where the content of the bar binds to an ObservableCollection and uses data templates to render the button bar.
I have tried a few ways of doing this so far but cannot figure out a way that gives me the visual behaviour I want. These are my requirements
1) Button to change background to a different Brush OnMouseOver
2) When button is selected, a different Brush is displayed as the background until a new button in the group is selected, like a togglebutton IsSelected behaviour
3) Only one button in the group can be selected at a time
The ways I have tried to do this so far are
1) Extending RadioButton with my own class, adding dependency properties for command and commandparameter. Setting all controls to have the same group Id. Data template to override display of radio button to make it look like a visual button with triggers for mouseover and isselected.
This works fine, except for one thing. Once you select a radio button in a group, there is no way to deselect all options in the radio button group. So if you navigate to "maintenance" and then click the sub menu for "Countries" for example, then you are displayed the country maintenance screen. If you then go to a different area of the app and select "Deal Entry" from the main menu, you are taken to the deal entry screen. If you then click "Maintenance", it displays the generic "maintenance" content and brings back the sub menu control for maintenance, where "Country" is selected in the radio button group, but this is undesirable. When you navigate back to Maintenance, it should deselect all sub menu options, display the generic maintenance landing page content and let you select a sub menu option before displaying that screens content. The first time you load Maintenance, nothing is selected, but once you have chosen an option, then there is no way to have nothing selected again when you reload the maintenance screen.
2) I then tried extending a ListBox, styling it with a horizontal stackpanel for the content, each listboxitem is a menubuttonViewModel. This allows me to only select a single option at a time and to clear the selection when you navigate away from the page. It also lets me change the background when you mouse over each listboxitem.
The bit I can't get working with the listbox is to have the background different on the IsSelected trigger. There seems to be some trigger on the default ListBoxItem template that overrides anything you specify in CSS so no matter what trigger I put on the listboxitem or menubuttonviewmodel style, the background simply does not change. I think I need to redefine the data and content template for listboxitem, but only have it apply for this listbox, so it can't be a global template change to all listboxitems - as I want to be able to use listboxes elsewhere in the app without inheriting this behaviour.
Can anyone give their thoughts on these two approaches and how to perhaps solve the issues I'm having to make one of them work in the way I want, particularly if you can advise how I can override the content/data template for the listboxitems in my style so they do not use the default triggers, and I can get the IsSelected trigger working for me?
If I understood correctly, you would want to clear the selection on the RadioButtons from the Sub-Menu each time you navigate back from another Main Menu option.
In order to solve this, you could have every Radio Button "unchecked" by manually setting the RadioButton´s IsChecked property value to false. A possible solution could be the following:
If you want to clear any checked option from the Sub-Menu everytime you navigate to a different section of the Main Menu, you could first notify to the Sub-Menu´s ViewModel by publishing an event using the EventAggregator after selecting and clicking a different MainMenu button, from the SelectionChangedEventHandler method of the Main Menu´s ViewModel.
Therefore, the Sub-Menu EventHandler of the published event would update each RadioButton´s IsChecked property value to false, which it could be accomplished by using a "Two-Way" Binding between each IsChecked property defined on the View, and each boolean "RadioButton1IsChecked" property implemented on the ViewModel.
I hope this helped you.

Buttons keeping their focus class after losing focus

I have some buttons in a bottom toolbar of a gridpanel that control adding, and removing records from the row-editing grid.
The handlers are pretty simple: "new" button creates an instance of the model, appends to the grid and then opens a row-editor on the new row; "edit" button just opens the selected row's row-editor; "remove" destroys the record from the store and refreshes the grid view.
For some reason these buttons don't lose the focus class that gives them a border when they have the focus. Here is a picture:
In the picture both the "New" button and the "Remove" button have the focus class, when I press the "Edit" button it also keeps the focus classes even after doing a complete row-edit operation and closing the row-editor.
I did find that when I mousedown on one of these permanently "focused" buttons and then mouseup away from it and then click something else the focus class goes away.
I know that I could put a blur handler for all button components in my respective controllers but I would have thought that this functionality was built in so I am asking to see if there is something I missed somewhere in the docs.
The classes that it won't let go of are these:
x-focus x-btn-focus x-btn-default-toolbar-small-focus
This is with ExtJS 4.1.0 in FF10 on Windows 7. But I did notice similar behavior in ExtJS 4.02 and 4.07, just haven't needed to handle it until now.
I found out what it was:
At some point in the handler chain for each of these buttons the button gets disabled. When a button is disabled in ExtJS it prevents the blur event from firing.
It was necessary to disable the buttons so the solution to simply add button.blur() in the handler was the correct way to do go about it.

Show Tooltip immediately after click

I've got a Tree with custom TreeViewItems. The TreeViewItems contains a CheckBox. When I click on a CheckBox the background logic decides whether the click was valid or not and if it was invalid a warning message should be shown.
I added a Tooltip to each TreeViewItem and set the visibility to Collapsed when doing declaration. The Tooltip should show the message but if I set it to Visible in the TvItems click event it doesn't appears immediately just after it gets the mouseOver event again. Its the same if I set the IsOpen property in the event.
How can I force the Tooltip to appear when I want in this case?
You can try to use the ToolTipService class to set the InitialShowDelay to 0. But i think this will also show the tooltip directly when you hover your mouse over the element.
Maybe you should reconsider this design, because i think what you want to do proves to be difficult in some circumstances or not usable.
If you want to do it on a mouse Click, i would use a attached behavior to hook the mouse click, and show the tooltip by hand, which can be accomplished by grabbing the ToolTip of your TreeViewItem and setting IsOpen to true.

Resources