How to create WPF button that drops down a listBox - wpf

I'm trying to create a button in main window that would look like a globe, which would allow user to select his/her location. I want it to display a listBox when clicked on it just below the button itself.
Any hints on how to do this?

Probably the simplest way to do this is restyle a ComboBox and then restyle the ToggleButton in the ComboBox and remove the editable textbox.
This will avoid you having the implement the functions of the ComboBox for your popup.
Try using this as a starting point.

Another Approach would be to use the Expander Control with a list box in it
Link
OR
You could play with the Listbox's visibility property

Related

How to hide arrow button in combobox?

Now I just want to dropdown the combobox via code.
IsDropDownOpen = true;
So how to hide (not disable) the arrow button in combobox?
To hide the ComboBoxToggleButton, you would have to edit a copy of the combobox template.
Right click on the combobox and select edit template. Select edit a copy and give it a name. (You may want to put the copy in a resource dictionary of it's own considering the content size)
The generated ComboBox style will have reference to two templates, ComboBoxTemplate and ComboBoxEditableTemplate.
In each template, you will find a ToggleButton with x:Name:toggleButton, that is the toggle button you want to hide.
You can remove it entirely, or make use of your WPF given Visibility property. Your call ;)
I would consider putting a textbox on top of the combobox and hiding that part of it.
Something like:
<Grid>
<ComboBox Name="YourCombo"/>
<TextBox Name="VisibleValueTextBox"/>
</Grid>
You can bind the text of VisibleValueTextBox to that of YourCombo.
When you drop it down, the dropdown will still be on top of everything.
I'm not sure what your full requirements are but this is a quick and perhaps rather dirty approach which could work.

ListBox Item style

I need to write a style for a listboxItem that will add a button on the right of the listboxitem when it is selected or mouse over. The button need to have a command binding as well .
This style need to be used in different places.
also the button won't have a border. but when the mouse is over the button , it will have a border.
How can i write this?
I tried to write a style, but i can't bind to the command of the button that is inside the style.
Code used: (sorry i wasn't able to paste my code normally here so it is here http://justpaste.it/1b9s)
It would be great to see some code but an option that should work is to create a DataTemplate. You can set it on ListBox ItemTemplate property and use it in the different locations where you may need it.

Silverlight TreeView in ComboBox (or just a custom dropdown control)

I was wondering if I can have a ComboxBox with a Treeview as the selector rather than a list?
I note that there is a ComboBox.ItemsPanelTemplate, but I don't know what I need to do to get this to work?
I could build a control 'from the ground-up' with a separate TextBox, Button and TreeView in a PopUp control, but wondered if there is an easier way.
Lee
Are you just wanting the combobox for presentation purposes regarding the treeview?
Why not use a treeview as is and just trigger the display via visibility or animation from a button or control of some sort?
I am working on similar theme as we speak. I am using the Expander control from the Silverlight Toolkit with a TreeView control inside it. When an item is selected in the TreeView, it sets the Header of the Expander and then collapses the Expander.
Initial tests indicate it's OK but as I say, just started with it myself. Will let you know if I hit any stumbling blocks.

How to 'get at' the WPF combobox PART_EditableTextbox because combobox not getting highlighted?

My WPF combobox is populated with a different set of strings each click of a button. There are other controls on the window as well. The combobox is the 'first' (top) in the window, but the text doesn't get highlighted. When the user tabs through the controls, the text DOES get highlighted, but when it's the first on the window, it doesn't.
Maybe i need to force a highlight on the individual textbox control 'within' the combobox itself, but how would i do this? I couldnt seem to find the internal 'structure' of this control anywhere. Could anyone help here?
Jack
to get the TextBox of Combobox you can use
TextBox TxtBox = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo);
I'm not sure it's the best solution, but you can use FrameworkElement.FindName to access the child control -- it's guaranteed to be present in a combobox, because it's a key constituent part of the control.
That stated, is it not better to try and call .Focus() on the control? That is likely why when you tab, the highlight is provided.
Another option is to derive from ComboBox, and expose the child text box as a property allowing you to set it's selection, or add a method directly to the combobox to set it for you.

WPF "flying" combobox

is it possible to create a combobox in wpf from code, which I could position wherever I want on the window?
In my case, I basically want to create something like a Autocomplete for DataGrid rows,...
Thanks!
TextBox supports auto complete, and you can create your datagrid's template column and you can specify the template with textbox which can interact and give you autocompletion.
if you put it in a <Popup> you can then position the popup wherever you want--it is not "bound" by a parent container.

Resources