I have a little problem with the combobox control: The binding of a list works absolutely well even if I change the list at runtime. My problem is that the length of the dropdown part does not change anymore after opening it for the first time. An example:
When the page is loaded the combobox contains four items. When I open it I see them all. After that I for example press a button and now the combobox contains seven items. But when I open it it I still see only the first four items and a scrollbar for the
rest...
I already tried UpdateLayout but that didn't do it. Does anyone have an idea how to change the listlength at runtime everytime the number of items changes?
Does that work for this scenario? It restricts the height, but only upto a maximum, and the initial height is set during the first binding.
Here we want the opposite - we want to expand the height of the DropDownList to fit all the added items in without using a scrollbar. MinDropDownHeight would seem to be the anser, but there is no such property!
I got this working by creating the whole thing in code like this, but it's not very satifactory:
public partial class Page : UserControl
{
ObservableCollection people;
ComboBox combo1;
public Page()
{
InitializeComponent();
people = new ObservableCollection();
people.Add(new Person() { Id = 1, Name = "Fred" });
people.Add(new Person() { Id = 2, Name = "John" });
people.Add(new Person() { Id = 3, Name = "Paul" });
people.Add(new Person() { Id = 4, Name = "Jane" });
people.Add(new Person() { Id = 5, Name = "Julie" });
CreateCombo();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
people.Add(new Person() { Id = 6, Name = "Eileen" });
LayoutRoot.Children.Remove(combo1);
CreateCombo();
}
private void CreateCombo()
{
combo1 = new ComboBox();
combo1.ItemsSource = people;
combo1.DisplayMemberPath = "Name";
LayoutRoot.Children.Add(combo1);
}
}
The combobox must be doing some work somwhere where it works out this height - we need to find out how to get it to do it again!
I'll have a look in reflector and see what I can find...
(If this has answered your question, "Mark as Answer" - many thanks)
Can you post the xaml and the code you are using so I can replicate it.
Hi Ian,
unfortunately it's code written for my employer... And too complex to put it into a small anonymous application. So, I think I have to go on trying by myself, yes?
I even tried a factor 100 and nothing happend. Also the other case that the second list is shorter than the first one makes no changes to the size. In that case I see some empty rows below the actual items. Absolutely no size update...
meykih
Participant
1049 Points
260 Posts
Databinding on combobox - layout update
Nov 11, 2008 11:40 AM | LINK
I have a little problem with the combobox control: The binding of a list works absolutely well even if I change the list at runtime. My problem is that the length of the dropdown part does not change anymore after opening it for the first time. An example:
When the page is loaded the combobox contains four items. When I open it I see them all. After that I for example press a button and now the combobox contains seven items. But when I open it it I still see only the first four items and a scrollbar for the rest...
I already tried UpdateLayout but that didn't do it. Does anyone have an idea how to change the listlength at runtime everytime the number of items changes?
ThanksMaike Ohlig
Please mark post as answer if it helped you
Ken Tucker
All-Star
23232 Points
3530 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 12:05 PM | LINK
Set the combobox's MaxDropDownHeight
Space Coast .Net User Group
meykih
Participant
1049 Points
260 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 12:13 PM | LINK
Doesn't work. Still no size update after the first opening...
Maike Ohlig
Please mark post as answer if it helped you
IanBlackburn
Contributor
2333 Points
371 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 12:20 PM | LINK
Hi Ken,
Does that work for this scenario? It restricts the height, but only upto a maximum, and the initial height is set during the first binding.
Here we want the opposite - we want to expand the height of the DropDownList to fit all the added items in without using a scrollbar. MinDropDownHeight would seem to be the anser, but there is no such property!
I got this working by creating the whole thing in code like this, but it's not very satifactory:
The combobox must be doing some work somwhere where it works out this height - we need to find out how to get it to do it again!
I'll have a look in reflector and see what I can find...
Cheers
Ian Blackburn
SilverlightForBusiness.net
IanBlackburn
Contributor
2333 Points
371 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 12:37 PM | LINK
Ok here is the answer:
The only thing left to do is work out the height of each row so you can calculate the correct Rect size.
Hope this helps.
Cheers
Ian Blackburn
SilverlightForBusiness.net
meykih
Participant
1049 Points
260 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 12:47 PM | LINK
I'm really sorry but my combodropdown still keeps its length set at first opening...
Maike Ohlig
Please mark post as answer if it helped you
IanBlackburn
Contributor
2333 Points
371 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 01:15 PM | LINK
Can you post the xaml and the code you are using so I can replicate it.
Cheers
Ian Blackburn
SilverlightForBusiness.net
meykih
Participant
1049 Points
260 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 01:38 PM | LINK
Hi Ian,
unfortunately it's code written for my employer... And too complex to put it into a small anonymous application. So, I think I have to go on trying by myself, yes?
Maike Ohlig
Please mark post as answer if it helped you
IanBlackburn
Contributor
2333 Points
371 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 01:45 PM | LINK
Did you try increasing the value here:
Cheers
Ian Blackburn
SilverlightForBusiness.net
meykih
Participant
1049 Points
260 Posts
Re: Databinding on combobox - layout update
Nov 11, 2008 01:50 PM | LINK
I even tried a factor 100 and nothing happend. Also the other case that the second list is shorter than the first one makes no changes to the size. In that case I see some empty rows below the actual items. Absolutely no size update...
Maike Ohlig
Please mark post as answer if it helped you