I have a combobox in WPF that I add items to at run-time (via a data binding to a List). I'd like to set the height of the dropdown box dynamically so that all (or most) of the items show. Unfortunately it seems that the height of the dropdown is set once and cannot be dynamically altered. It always seems to be the same size.
Is there some relatively straightforward to adjust the dropdown height?
Yes, I've tried setting it after adding the items to the combobox. In the debugger it looks like the new value is there. However, when I open the dropdown, it drops down to a size of its own choosing. I've tried exaggerating the MaxDropDownHeight and have even set it to "Auto" to no avail.
The property MaxDropDownHeight is a dependency property, on the combo box that controls the height of the drop down list. Since it's a dependency property, it's value can be set dynamically.
Have you tried setting this value?
MaxDropDownHeight="Auto"
For me, the issue was that ComboBox dropdown had height of 95 pixels regardles of the amount of items.
My data source for the ComboBox was a Collection<>, but after changing it to ObservableCollection<>, the ComboBox dropdown opens showing all items.
Now also the MaxDropDownHeight property works just fine.
Ref: This comment in here Make the dropdown of a combobox be shorter?
Set your ComboBox's Style={x:Null} to ensure that you don't have a style issue affecting the drop-down panel size.
Related
I have a dropdownlist combobox that uses an ItemTemplate to display information. When the dropdown of the combo is open, I want the user to be able to type things that I will search the data for. Then I'd like to highlight the item (and potentially scroll it into view), but NOT select it (selection in this case is expensive and should only occur when the user presses Enter once he's found the right entry).
Essentially this is how a vanilla combobox behaves and I want to do this for my templated one that searches differently.
I've have an AttachedProperty that does the searching correctly, but I can't figure how to set the highlighted item (IsHighlighted is read-only).
This is not a cosmetic issue only, since Enter should select the highlighted item.
Any ideas?
If you can add a dependency property to the object in the list you are displaying that holds a bool value for the "ShowHighlighted" state, you could then add a trigger to your ItemTemplate that changes the Background Brush based upon the value of ShowHighlighted.
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 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.
I'm trying to achive displaying the RowDetailsTemplate of a Silverlight DataGrid depending on a bool Property, bound to a CheckBox Control's IsChecked Property. Insinde of my RowDetailsTemplate there is a single custom UserControl, containing further Controls.
Since the DataGrid only allows a global setting (RowDetailsVisibilityMode) Some code-behind is needed. I've implemented a solution based on Rorys Reply (and using a behaviour-technique) which actually works.
Unfortunately, The DataGrid doesn't remember the individually shown or hidden Rows on sorting. The checkbox remains selected, but the Row collapses. Further, no event like "OnAfterSort" or something similar seems to exist, where i could "Refresh" the visibility settings in a loop.
Another idea was to bind the Visibility of my custom Details-UserControl to the CheckBox bound value. This actually works (when settings RowDetailsVisibilityMode to "Visible"), but I'm not able to get rid of this weird behaviour: When the CheckBox is checked, the Detail Template expands and the detail UserControl appears. Nice. When the CheckBox is unchecked again, the UserControl disappears (Visibility is set to Collapsed) but the Row doesn't collapse and the blank space remains (as it would be set to Hidden not Collapsed).
Do you have any ideas?
I hope it's ok I didn't post any code samples, the implementation is pretty easy and I believe that the problem doesn't actually lie in a coding mistake i made. You can setup a simple DataGrid quickly like in this perfect MSDN Example. Starting from here, it's easy to test both described behaviours!
Really big thanks in advance,
- Thomas
I'm working in Silverlight, trying to figure out how to set a grid cell font color based on the contents of the cell.
I have an ObservableCollection bound to a DataGrid, and my items implement INotifyPropertyChanged so the grid updates as I change the values; it's all working perfectly, including letting me sort items and keep the sorting while I update the underlying items.
I know I can use the LoadingRow event to change colors, but the only way I can get the event to fire is by changing the grids datasource, in which case my sorting goes out the window.
So, what I really want is a way to either
loop the rows in the datagrid,
find the cell I need, and change
it's color or
implement a custom
column that I can use to dynamically
set the color.
The problem is how to actually do either of those things :).
You should use databinding for this.
Bind your cell font color to the content of the cell
Create a converter IValueConverter that converts the value to a color depending from your needs
See here for a good example
http://weblogs.asp.net/joewrobel/archive/2009/01/25/conditional-formatting-in-the-silverlight-datagrid.aspx