I'm new in wpf, want to develop app in c#, where combobox will have 3 subitem(i.e audi, bmw and custom) selecting custom will again show the combobox will have 2 radio buttons, and one combobox in it.
So combobox will have item and some item again will have subitem. This is similar to menu and some menu item has again submenu, e.g CAR combobox will have 3 combo item i.e. audi,bmw and customise car. Selecting customize car will show popup, having 2radio btn and one combobox. so user can select either audi, bmw or customize car option
I'm assuming that the options of the main ComboBox are in some way hard-coded. Whether that's in xaml or in code. Either way I would define a method for the SelectionChanged event on the combo box and open a new window, when Custom is selected.
<ComboBox Name="..." ..., SelectionChanged="carType_SelectionChanged" />
Defining this here in the xaml will automatically generate the carType_SelectionChanged method in the code for this window. If it doesn't it will look something like this:
carType_SelectionChanged(object sender, SelectionChangedEventArgs e)
This popup window can be another wpf window that is called by the main. This can contain two radio buttons and a ComboBox populated in the same way that the main window's combobox is. My understanding of what you want from this popup window is that the ComboBox displays the same information. However for this I wouldn't have the check on the custom option to open a popup, as this has already occurred at this point.
If you need help calling the new window inside the SelectionChanged method, let me know and I can point you in the right direction for doing that.
Related
I have a ListBox in a Silverlight Application. I'm trying to make an editable listbox, so I use an ItemTemplate to have the controls i need in each item, like a textBox and buttons, and its working fine.
I'd like to have a line at the end of the Listbox with a button to add new items. Since this item won't be related to any of my domain classes, I'm using a plain object as a 'Filler', and then I have code that identify this item to show the button correctly.
myListBox.Items.add(new object());
The problem is that I want this "new Record" item to be kept always at the end of listbox, so when I need to insert a new domain record, i use this code:
myListBox.Items.Insert(myListBox.Items.Count - 1, domainItem);
When I debug the myListBox.Items collections, it is in the right order, with the "add new" button at the end, but the listbox is displaying this button at the beggining. Why are my items beeing displayed in a different order than the Items collection?
Unless there is a specific reason, instead of trying to put the button into the listbox collection itself you would be best to create a new control with the button outside and below the listbox. You can always style the button to look as though it's within the listbox if required.
Is there a reason why you are not using a datagrid because it would remove all your ordering problems and it would allow you to edit the entries.
The datagrid is bound to an ObservableCollection which automatically connects your editable fields to the GUI.
Cheers,
I have Combo boxes inside a list box and whenever the list box is scrolled and the combo box is scrolled off of the screen the list box is firing a selection change event on the combo box and setting the selected index of the combo box to null.
If I scroll back and forth multiple times you will see the selected item display and be removed by scrolling the list back and forth.
Does anyone have an idea on ow to fix this? I need the combo box to retain the selected index.
I have even changed the collection that holds the Combo-box data to a list from an observable collection and it still does the same thing.
I am using silver light v4, .net 4
Thanks...
This is probably a result of the default virtualising nature of the ListBox. As items scroll off the displayed the items are actually removed from the Visual Tree. If you don't have too many items in the list set the ItemsPanel property of the ListBox to an ItemsPanelTemplate containing a simple StackPanel.
Better would be to cease using the selection change event in this scenario, use a binding on the SelectedItem property instead.
I had the same issue, but with a datagrid.
I tried this (preferable solution), but it didnt work for me.
Silverlight ComboBox and SelectedItem
So i had to go with this....
http://forums.silverlight.net/post/396922.aspx
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
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.
I have a ComboBox with a DataTemplate. The DataTemplate has two controls, each of which has a ToolTip attached to it. The list of items of the ComboBox has the tooltips as expected when you hover over each control. But the selected item area on top of the ComboBox does not display the tooltips, though the controls are rendered as expected. Is there a way to force the tooltips to be displayed?
If you're using Mole or something similar, make sure that your control with the attached ToolTIp has IsHitTestVisible="True". Otherwise, the control is not listening for mouse events and will not recognize that the ToolTip should be shown in the first place.
You may also want to look at binding the ToolTip of the selected item to the ContentPresenter in the ComboBox since, after selection, your SelectedItem becomes the content of the ComboBox. You may need to override the ComboBox template and make sure the ContentPresenter can accept mouse input in order to force your ToolTip's visibility.