(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .

Silverlight Custom ComboBox

(32 votes)
Doug Blackmore
>
Doug Blackmore
Joined Sep 11, 2008
Articles:   1
Comments:   8
More Articles
56 comments   /   posted on Sep 11, 2008
Categories:   Controls
Tweet This!

Note: This article is submitted by Doug Blackmore for Silverlight: Write and Win contest.Thanks a lot, Doug! Hello All, Please drop a comment if you like it.

It is time to vote now! Please, choose your favorite articles and enter your vote by going to contest page. Thank you!

This article is compatible with the latest version of Silverlight.

In this article I will show you how to implement custom ComboBox that includes templating, data binding, and auto complete functionality.

View the Demo

Download Source Code

Getting Started

The initial code for the combo box was obtained by reflecting (http://www.red-gate.com/products/reflector/) on the Silverlight ListBox control. This provided the initial xaml and C# for the dropdown portion of the combo box, so we renamed the controls from ListBoxItem to ComboBoxItem and ListBox to ComboBox. To complete the control, we added a TextBox and a Button.

Populating the Combo Box

The ComboBoxItem element has a Content property that can be used to populate the combo box in the XAML markup file.

<local:ComboBoxItem Content="British Columbia" />
<local:ComboBoxItem Content="Alberta" />
<local:ComboBoxItem Content="Saskatchewan" />

In code, you can use the Add() method of the Items property on the Combo Box.

this.cboProvinces.Items.Add("British Columbia");
this.cboProvinces.Items.Add("Alberta");
this.cboProvinces.Items.Add("Saskatchewan");

You can also set the ItemsSource property of the combo box.

IList<Province> Provinces = new List<Province>();
Provinces.Add(new Province("British Columbia", "BC", new DateTime(1871, 7, 20)));
Provinces.Add(new Province("Alberta",          "AB", new DateTime(1905, 9, 1)));
Provinces.Add(new Province("Saskatchewan",     "SK", new DateTime(1905, 9, 1)));
this.cboProvinces.ItemsSource = Provinces;

Data Templates

For more complex dropdown combo box items, you can define a DataTemplate in your XAML.

<local:ComboBox.ItemTemplate>
    <DataTemplate>
        <StackPanel Margin="0,3,0,3">
            <StackPanel Orientation="Horizontal">
                <TextBlock Width="150"
                           Text="{Binding Path=FullName}"
                           VerticalAlignment="Center" FontSize="14"  />
                <TextBlock Text="{Binding Path=Abbreviation}"
                           HorizontalAlignment="Right"
                           VerticalAlignment="Center"
                           FontSize="12"  />
            </StackPanel>
            <TextBlock Text="{Binding Path=DateOfConfederation, Converter={StaticResource DateConverter}}"
                       Foreground="DarkRed"
                       FontSize="10"  />
        </StackPanel>
    </DataTemplate>
</local:ComboBox.ItemTemplate>

Here’s the resulting dropdown:

Data Binding

Of course, once a selection has been made from a rather complex dropdown, the entry in the text box portion of the combo box is the ToString() result of the selection.

There are 2 ways to bind the selection to the text box:

DisplayMemberPath

Specify a property of the selection object.

<local:ComboBox x:Name="cboProvinces" Width="200" DisplayMemberPath="Description"  />

DisplayMemberBinding

Specify the binding to use when displaying the selected item in the text box.

<local:ComboBox x:Name="cboProvinces"
                DisplayMemberBinding="{Binding DateOfConfederation}">

This becomes more useful when a type converter is specified.

<local:ComboBox x:Name="cboProvinces"
                DisplayMemberBinding="{Binding DateOfConfederation,
                Converter={StaticResource DateConverter}}">

If both DisplayMemberPath and DisplayMemberBinding are specified, only DisplayMemberPath is used.

Auto Complete

The auto-complete functionality is available by default. Each item in the drop down is compared with the text in the text box. If there’s a match, the item’s Visibility property is set to Visible. Otherwise, it’s set to Collapsed.

Initial dropdown

Type ‘n’ in the text box

Type ‘ne’ in the text box

“Auto” DropDownWidth

The width of the dropdown defaults to the width of the combo box itself. You can specify a smaller or larger value by specifying a number, or you can auto-size the dropdown by specifying a DropDownWidth of “Auto”.

<local:ComboBox x:Name="cboProvinces" Width="250"  />

 

<local:ComboBox x:Name="cboProvinces" Width="250" DropDownWidth="200"  />

 

<local:ComboBox x:Name="cboProvinces" Width="250" DropDownWidth="300"  />

 

<local:ComboBox x:Name="cboProvinces" Width="250" DropDownWidth="Auto"  />

 

Processing the Selection

Subscribe to the SelectionChanged event to process the selection. 

private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    object selectedItem     = this.cboProvinces.SelectedItem;
    this.txtSelection.Text  = (selectedItem == null)
                                ? string.Empty
                                : ((Province)selectedItem).Description;
}

Summary

We hope this custom implemented control tides you over. If you are so inclined, the source included here may give you a little insight into writing a control of your own.

The WorkSight Blog has just started, but drop by or subscribe. Our intent is to publish additional articles on software design and development.


Subscribe

Comments

  • -_-

    RE: Silverlight ComboBox


    posted by Eugen on Sep 11, 2008 12:45

    Looks very good indeed.

    However one issue you didn't solve, when combobox is expanded and you click somewhere else on the Silverlight screen it shall hide automatically.

  • -_-

    RE: Silverlight ComboBox


    posted by soundbox on Sep 11, 2008 16:05

    great job

    how to set the default selecteditem using xaml?

    to collapse the expanded combobox, add a timer to combobox class,   let all the child control have two event-handerler, mouse-enter( to set timer off) and mouse-leave(to set timer off),  then  the timer will do what you wish

  • -_-

    RE: Silverlight ComboBox


    posted by soundbox on Sep 11, 2008 16:07

    sorry, it should be  "mouse-leave(to set timer on)" 

  • dougblackmore

    RE: Silverlight ComboBox


    posted by dougblackmore on Sep 11, 2008 18:52

    Eugen,

    You're right - we did handle the 'press ESC to close' and the 'click on another combo to close and already-open-combobox' scenarios. I'll take a look.

  • dougblackmore

    RE: Silverlight ComboBox


    posted by dougblackmore on Sep 11, 2008 18:59

    soundbox,

    To set the default selection via xaml, just set the IsSelected property on the ComboBoxItem (IsSelected="True")

  • dougblackmore

    RE: Silverlight ComboBox


    posted by dougblackmore on Sep 11, 2008 19:06

    Eugen,

    We did handle the case where focus moves to another control (in the ComboBox::LostFocus event). What is not handled is the case where a click is done on the main Silverlight surface (the 'background').

  • -_-

    RE: Silverlight ComboBox


    posted by soundbox on Sep 11, 2008 21:36

    Thank you for your reply.
    Sorry for my poor description, it is not so clear that I make you mistake...
    Define cboProvinces3 as follow, I want to display "Alberta" the first time cboProvinces3 is shown.
    The problem is:
     "Alberta" is dynamic( eg. binding to a variable assuming its value be unique in the ItemSource )
    in another word, some comboboxes  having the same ItemSource as cboProvinces3  have different   "Alberta" to be the "default SelectedItem"
    Hope it is clear enough.

    xaml

    <StackPanel Orientation="Horizontal">
                <controls:ComboBox x:Name="cboProvinces3" Width="150" DropDownWidth="Auto" Margin="10" />
                <TextBlock Text="Populated from code; DropDownWidth='Auto' (dropdown wider than combo box)" VerticalAlignment="Center" Margin="5" 
    DisplayMemberPath="FullName"
    SelectedItem="Alberta"
    />
    </StackPanel>

    c#

    IList<Province> Provinces = new List<Province>();
                Provinces.Add(new Province("British Columbia",      "BC", new DateTime(1871, 7, 20)));
                Provinces.Add(new Province("Alberta",                        "AB", new DateTime(1905, 9, 1)));
                Provinces.Add(new Province("Saskatchewan",          "SK", new DateTime(1905, 9, 1)));
                Provinces.Add(new Province("Manitoba",                    "MB", new DateTime(1870, 7, 15)));
    cboProvinces3.ItemSource=Provinces;

  • -_-

    RE: Silverlight ComboBox


    posted by soundbox on Sep 11, 2008 22:43

    I overwrite the Province.Equals() method and Combobox.GetComboBoxItemForObject(), now 
    in c#
    cboProvinces3.SelectedItem=new Province("Alberta",                        "AB", new DateTime(1905, 9, 1));
    works well, but I still do not know how to set the SelectedItem Property in xaml directlly.

  • -_-

    RE: Silverlight ComboBox


    posted by henrik on Sep 21, 2008 04:09

    Looks great!

    I've tried to put just the combobox code files, generic.xaml and the arrow-image into a silverlight library, to reference the stuff in my silverlight project. Works during runtime, but does not work in the XAML editor in VS2008 - it tells me I'm missing an assembly reference - which i do not.

    Have you experienced this one?

  • -_-

    RE: Silverlight ComboBox


    posted by Doug on Sep 21, 2008 07:43

    No, I haven't seen that one. Which assembly does it say you're missing?

  • -_-

    RE: Silverlight ComboBox


    posted by henrik on Sep 24, 2008 07:59

    The silverlight assembly I created. I called it Silverlight.Controls.dll maintaining your Namespace.

  • dougblackmore

    RE: Silverlight ComboBox


    posted by dougblackmore on Sep 24, 2008 12:28

    Sorry henrik, you're not giving me a lot to go on here. From what I understand, you've copied the ComboBox.cs, ComboBoxItem.cs, downarrow.png and generic.xaml to your SilverLight.Controls.dll project and kept the WorkSight.Control namespace. In VS2008, you're getting a 'missing SilverLight.Controls reference' error message?

  • -_-

    RE: Silverlight ComboBox


    posted by Mark Aitken on Sep 25, 2008 06:44

    Hi,

    I've added the 4 files to my own control library, changed the namespaces etc.  to match in with my controls but when I add a combobox to my project I get an error message saying "Value does not fall within the expected range"  Any Ideas?

  • dougblackmore

    RE: Silverlight ComboBox


    posted by dougblackmore on Sep 25, 2008 09:08

    Mark,

    In generic.xaml, it's possible you may not have made the appropriate change on line 159 once you changed the namespace. The line currently reads:

         <Image Stretch="None" Source="/ComboBoxDemo;Component/ComboBox/downarrow.png" />

    You can either change the namespace, or change the line to the following:

         <Image Stretch="None" Source="ComboBox/downarrow.png" />

    The latest source on our website has this fix + some others:

        http://worksightblog.com/?p=72

    Let me know if this helps.

  • -_-

    RE: Silverlight ComboBox


    posted by Alok Varia on Sep 26, 2008 07:26

    Hi,

    First its very good control and easy to implement..i have facing one issue...when i select something and tab out using tab key it removes all the selection choice apart from what i have selected...any ideas why??

  • -_-

    RE: Silverlight ComboBox


    posted by Alok Varia on Sep 26, 2008 07:29

    I just did testing on your sample code same issue l00ks like a bug....any quick fix to it??

    Thanks in advance..

    Alok Varia

  • -_-

    RE: Silverlight ComboBox


    posted by Doug on Sep 27, 2008 08:37

    Alok,

    In the ComboBox::OnKeyDownInternal method, add the following inside the switch statement:

       case Key.Tab:
          this._applyFilter = false;
          return false;
     

  • -_-

    RE: Silverlight ComboBox


    posted by oneone on Sep 30, 2008 23:48

    can it put into the datagrid ?

    like this

                <my:DataGrid x:Name="myDataGrid" Width="500" Height="500" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="Visible" >
                    <my:DataGrid.Columns>
                        <my:DataGridTextColumn Header="FullName" DisplayMemberBinding="{Binding FullName}" />
                        <my:DataGridTextColumn Header="Abbreviation" DisplayMemberBinding="{Binding Abbreviation}" />

                        <my:DataGridTemplateColumn >
                            <my:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <controls:ComboBox x:Name="combo" FontFamily="Arial" FontSize="12" Width="250" Margin="2" VerticalAlignment="Center" />
                                </DataTemplate>
                            </my:DataGridTemplateColumn.CellTemplate>
                        </my:DataGridTemplateColumn>

                    </my:DataGrid.Columns>
                </my:DataGrid>

  • -_-

    RE: Silverlight ComboBox


    posted by Doug on Oct 01, 2008 07:21

    Sure, try the following:

    Page.xaml:

    <UserControl x:Class="ComboBoxDemo.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:WorkSight.Controls"
        xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
        xmlns:ComboBoxDemo="clr-namespace:ComboBoxDemo"
        Width="Auto" Height="300">

        <UserControl.Resources>
            <ComboBoxDemo:ProvinceLookup x:Key="provinceLookup"/>
        </UserControl.Resources>

        <StackPanel x:Name="LayoutRoot" Background="White">
            <data:DataGrid x:Name="dataGrid" Width="Auto" Height="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="Visible" AutoGenerateColumns="False" >
                <data:DataGrid.Columns>
                    <data:DataGridTextColumn Header="FullName" DisplayMemberBinding="{Binding Description}" />
                    <data:DataGridTextColumn Header="Abbreviation" DisplayMemberBinding="{Binding Abbreviation}" />

                    <data:DataGridTemplateColumn Header="Description" >
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <controls:ComboBox x:Name="combo"
                                                   FontFamily="Arial"
                                                   FontSize="12"
                                                   Width="250"
                                                   Margin="2"
                                                   VerticalAlignment="Center"
                                                   SelectedItem="{Binding FullName, Mode=TwoWay}"
                                                   ItemsSource="{Binding Provinces, Source={StaticResource provinceLookup}}"
                                />
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                    </data:DataGridTemplateColumn>
                </data:DataGrid.Columns>
            </data:DataGrid>
        </StackPanel>
    </UserControl>
     

    Page.xaml.cs (use the existing Province class):

        public partial class Page
        {
            public Page()
            {
                InitializeComponent();

                IList<Province> provinces = new List<Province>();
                provinces.Add(new Province("British Columbia", "BC", new DateTime(1871, 7, 20)));
                provinces.Add(new Province("Alberta", "AB", new DateTime(1905, 9, 1)));
                provinces.Add(new Province("Saskatchewan", "SK", new DateTime(1905, 9, 1)));
                provinces.Add(new Province("Manitoba", "MB", new DateTime(1870, 7, 15)));
                provinces.Add(new Province("Ontario", "ON", new DateTime(1867, 7, 1)));
                provinces.Add(new Province("Quebec", "QC", new DateTime(1867, 7, 1)));
                provinces.Add(new Province("Newfoundland", "NL", new DateTime(1949, 3, 31)));
                provinces.Add(new Province("Prince Edward Island", "PE", new DateTime(1873, 7, 1)));
                provinces.Add(new Province("New Brunswick", "NB", new DateTime(1867, 7, 1)));
                provinces.Add(new Province("Nova Scotia", "NS", new DateTime(1867, 7, 1)));
                provinces.Add(new Province("Nunavut", "NU", new DateTime(1999, 4, 1)));
                provinces.Add(new Province("Yukon", "YT", new DateTime(1898, 6, 13)));
                provinces.Add(new Province("Northwest Territories", "NT", new DateTime(1870, 7, 15)));
                this.dataGrid.ItemsSource = provinces;
            }
        }

        public class ProvinceLookup
        {
            public IList<string> Provinces
            {
                get
                {
                    IList<string> provinces = new[] {
                                              "British Columbia", "Alberta", "Saskatchewan", "Manitoba", "Ontario", "Quebec",
                                              "Newfoundland", "Prince Edward Island", "New Brunswick",
                                              "Nova Scotia", "Nunavut", "Yukon", "Northwest Territories"
                                          };
                    return provinces;
                }
            }
        }
     

  • -_-

    RE: Silverlight ComboBox


    posted by oneone on Oct 01, 2008 20:04

    perfect  !!

    thanks !! 

  • -_-

    RE: Silverlight ComboBox


    posted by Alok Varia on Oct 02, 2008 07:48

    Doug thanks for the prompt reply..To all the readers silverlight 2.0 beta is moved to RC and Msft have included combox box control..i havent used it but hoping i will be bug free..

    Alok Varia

  • -_-

    RE: Silverlight ComboBox


    posted by oneone on Oct 07, 2008 22:56

    Hi !

    could you teach me how to get the row data ?

    my code like this, i want when TextBox's text change, then get ComboBox's value, and that row's data

    <my:DataGrid x:Name="myDataGrid" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
        <my:DataGrid.Columns>
            <my:DataGridTextColumn Header="ID" DisplayMemberBinding="{Binding ID}" />
            <my:DataGridTextColumn Header="Ages" DisplayMemberBinding="{Binding Ages}" />

            <my:DataGridTemplateColumn Header="" >
                <my:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Width="Auto" Height="60" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal" Background="#FFDBF7E8" >
                           
                            <TextBox Width="80" Height="25" FontFamily="Arial" FontSize="12" Margin="8" TextChanged="RunBetChange" />

                            <controls:ComboBox FontFamily="Arial" FontSize="12" Width="100" Margin="2" VerticalAlignment="Center" SelectedIndex="1"
                                               SelectedItem="{Binding Food, Mode=TwoWay}"
                                               ItemsSource="{Binding Food, Source={StaticResource food}}" />
                        </StackPanel>
                    </DataTemplate>
                </my:DataGridTemplateColumn.CellTemplate>
            </my:DataGridTemplateColumn>

        </my:DataGrid.Columns>
    </my:DataGrid>

    thanks for your help !

  • -_-

    RE: Silverlight ComboBox


    posted by oneone on Oct 07, 2008 23:19

    sorry, forgot one button

    when "Save" button press, to get ComboBox's index, and TextBox's value, and that row data

    <Button x:name="Save" Content="Save" Width="80" Height="Auto" Click="SaveClick" />

    <my:DataGrid x:Name="myDataGrid" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
        <my:DataGrid.Columns>
            <my:DataGridTextColumn Header="ID" DisplayMemberBinding="{Binding ID}" />
            <my:DataGridTextColumn Header="Ages" DisplayMemberBinding="{Binding Ages}" />

            <my:DataGridTemplateColumn Header="" >
                <my:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Width="Auto" Height="60" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Horizontal" Background="#FFDBF7E8" >
                           
                            <TextBox Width="80" Height="25" FontFamily="Arial" FontSize="12" Margin="8" TextChanged="TextChange" />

                            <controls:ComboBox FontFamily="Arial" FontSize="12" Width="100" Margin="2" VerticalAlignment="Center" SelectedIndex="1"
                                               SelectedItem="{Binding Food, Mode=TwoWay}"
                                               ItemsSource="{Binding Food, Source={StaticResource food}}" />
                        </StackPanel>
                    </DataTemplate>
                </my:DataGridTemplateColumn.CellTemplate>
            </my:DataGridTemplateColumn>

        </my:DataGrid.Columns>
    </my:DataGrid>

    Thanks very much !!

  • -_-

    RE: Silverlight ComboBox


    posted by Aref on Oct 19, 2008 21:05

    Mr. doug I am using the combo box but one prob i am facing that after selecting item from combobox i can't change the itemsource . If I try to do that the screen becomes blank. or system crashes. No error message showing. But if i don't select any item then i can change the itemsource.

  • -_-

    RE: Silverlight ComboBox


    posted by Quest4Denali on Dec 20, 2008 12:22

    Seems like Silverlight 2.0 has caused some issues with the control.  Has anyone been successful in implementing in 2.0?

  • -_-

    RE: Silverlight ComboBox


    posted by al011757@hotmail.com on Feb 07, 2009 13:05

    Hello when I try to use the DropDownWidth="300"  property, the compiler fails, I'm using Silverlight 2, Silverlight tools 2 SP1, do you know whats is wrong here?

  • -_-

    RE: Silverlight with express edition


    posted by Jen on Mar 30, 2009 21:39
    Is silverlight a freeware tools? Can I use silverlight with express edition?
  • -_-

    RE: Silverlight ComboBox


    posted by goldbishop on May 23, 2009 16:08
    Need to update the source as it is currently not working for SL2....may want to take a step forward and look at porting this to SL3 since it is in beta.  But overall its information on how to utilize the drop down box into SL.
  • -_-

    RE: Silverlight ComboBox


    posted by seb on Jul 02, 2009 12:55

    Hi,

    once you have databinded your combobox:

    cboProvinces3.ItemSource=Provinces;

    How can you add a row, like "Select a province" at the top ?

    I've tried something like:

    cboProvinces3.InsertAt(0, "[Select]");

     

    but that gives me a System.InvalidOperationException: Operation not supported on read-only collection.

    error.

     

    Any thoughts?

     

    thanks,

    Seb

     

     

     

  • -_-

    RE: Silverlight ComboBox


    posted by Aki on Aug 26, 2009 06:50
    Ive added a combobox which has the years of graduation from 1999 to 2009, when the user chooses lets say 1999 from the combobox, it will automatically concatenate file name to 1999_fileName.jpg.

    any idea how i can do that?

  • -_-

    RE: Silverlight ComboBox


    posted by Matt on Sep 18, 2009 17:32
    Great work. Developing a combobox can be boring but is necessary for most applications. Thank you so much for writing up this great tutorial on how to do it. Keep them coming - us developers can use all the help we can get.

    Thanks, Matt (Visual Basic 6)


  • -_-

    RE: Silverlight ComboBox


    posted by ArnieB on Oct 27, 2009 19:20
    This looks pretty good, but I have trouble getting it running in SL3.  Does anyone have a demo compiled with SL3?
  • -_-

    RE: Silverlight ComboBox


    posted by dougblackmore on Oct 27, 2009 20:18
    We're updating the ComboBox to work with SL3. I'll post here when it's ready (very shortly now).
  • -_-

    RE: Silverlight ComboBox


    posted by Friso on Nov 01, 2009 13:08

    Hi Doug, I am looking forward to the SL3 version!

    For what I see now: great work!

  • -_-

    RE: Silverlight ComboBox


    posted by silverlame on Nov 18, 2009 05:36
    I want to have a default "ANY" value in my combo box with a value of null.

    That way i know if no item has been selected when i click search or whatever.

    It seems to be ridiculously weak that once i've selected an item in a combobox i can't unselect it.

     

     

  • dougblackmore

    Silverlight ComboBox updated to SL3


    posted by dougblackmore on Dec 09, 2009 04:48
    We updated the ComboBox to Silverlight 3. You can find the article, demo and code at http://www.studio6software.com/blog.

    Regards,
    Doug

  • -_-

    RE: Silverlight ComboBox


    posted by Kamlesh on Jun 08, 2010 15:11

    hello sir,

    can u tell me how to remove a selected item from downdown list in silverlght.bcz i have one drown down box and it has 10 items so if i select 4th entry so 4th item should automatically deleted. it cant give the 4th item.

    so please help me... Thanking you.

  • -_-

    Silverlight ComboBox


    posted by Vikas on Jun 22, 2010 10:09

    how to display text in combobox in silverlight

    you can display selected value of combobox into textbox in silverlight

    TextBox1.Text= (cmbApplicationStatus.SelectedItem as ComboBoxItem).Content.ToString();

    here, cmbApplicationStatus is Name of your combobox

    thank you

  • -_-

    RE: Silverlight ComboBox


    posted by Bond on Aug 05, 2010 17:38

    When you have a List<DateTime> that you bind to a ComboBox by setting the ItemsSource how can you format the items?

    Thanks!

  • -_-

    RE: Silverlight ComboBox


    posted by disgruntledsilverlightdev on Sep 01, 2010 13:14

    Be warned this doesn't compile in Silverlight 4, as the Microsoft Silverlight team have actually changed the virtual method signatures of TypeConverter (plus a whole host of other compile errors).

  • lnikolov

    RE: Silverlight Custom ComboBox


    posted by lnikolov on Jan 24, 2011 09:58
    The article has been updated to the latest version of Silverlight and Visual Studio.
  • -_-

    RE: Silverlight Custom ComboBox


    posted by Anil Maurya on Feb 08, 2011 12:59

    One of the best code i ever found ...keep it

    Thanks for Help!!

  • -_-

    RE: Silverlight Custom ComboBox


    posted by Eric Carlson on Mar 24, 2011 17:58
    Excellent! Thank you for posting!
  • -_-

    Updated but still useful


    posted by Colin P on Apr 22, 2011 15:08
    As was said above this article is a bit outdated now, but I could still learn a lot from it. I plan on adapting this to use on my VB.NET Tutorials site. Its nice to have another developer explain things so well.
  • -_-

    Full screen mode


    posted by Sergio on May 05, 2011 14:04
    Control doesn't work correctly in full screen mode !?
  • -_-

    Full screen mode


    posted by Sergio on May 05, 2011 14:05
    Control doesn't work correctly in full screen mode !?
  • Gigatron

    Re: Silverlight Custom ComboBox


    posted by Gigatron on Sep 15, 2011 16:02

    Hi 

    I'm using SL5 (tried in 4 as well) 

    In the property of the combo box there is no DropDownWidth

    whats am i doing wrong?


  • xidius

    Re: Silverlight Custom ComboBox


    posted by xidius on Oct 25, 2011 18:48

    i found behaviour error - 

    when i use this comboBox inside Expander- if i collapse expander when ComboBox showing Popup List, this Popup will still exist  on the screen. 

  • Gigatron

    Re: Silverlight Custom ComboBox


    posted by Gigatron on Oct 26, 2011 08:06

    this is a workaround to fix the width of the popup

     protected override Size ArrangeOverride(Size finalSize)
            {
                if (popup != null && validationElement != null)
                {
                    Grid validationElementGrid = validationElement.GetVisualDescendants().OfType<Grid>().FirstOrDefault();
                    double finalWidth = validationElementGrid.Width + validationElementGrid.Margin.Left + validationElementGrid.Margin.Right;
                    contentBorder = popup.Child as Border;
                    if (contentBorder == null)
                        return base.ArrangeOverride(finalSize);
                    contentBorder.Width = finalSize.Width - finalWidth;
                                }
                return base.ArrangeOverride(finalSize);
            }
  • durga

    Re: Silverlight Custom ComboBox


    posted by durga on Nov 15, 2011 14:56
    It is good but can we use this in silverlight 4.0
  • Gigatron

    Re: Silverlight Custom ComboBox


    posted by Gigatron on Nov 15, 2011 15:07

    hi

    Yes it works in 4 and 5

  • EnKiu.Minh

    Re: Silverlight Custom ComboBox


    posted by EnKiu.Minh on Nov 17, 2011 11:46
    I have an user control (like TreeView), and my purpose is adding this control as a content of Combo box, can you give me an example?
  • EnKiu.Minh

    Re: Silverlight Custom ComboBox


    posted by EnKiu.Minh on Nov 17, 2011 11:48
    I have an user control (like TreeView), and my purpose is adding this control as a content of Combo box, can you give me an example?
  • yoosufshanij

    Re: Silverlight Custom ComboBox


    posted by yoosufshanij on Jun 09, 2012 11:26

    thank u for the wonderfull control......but i found that combobox.selectedindex = -1 does not work....cud u advise me how to do that.

     

  • CongTuBot

    Re: Silverlight Custom ComboBox


    posted by CongTuBot on Sep 30, 2012 12:39
    I just wonder if it's possible to prevent dropdown when click every where on the combobox but togglebutton?
  • iloveewan

    Re: Silverlight Custom ComboBox


    posted by iloveewan on 15:26

    great control! but i got some problem when i copy them to my project. in the drop down , it display the class name (ComboBoxDemo.Province) instead of formatted by item template. please give me some sugguestion. I copied all those files. Instead of writing style in generic.xaml , I created a sub folder under theme folder for styles. please give me some advice. thanks 

Add Comment

Login to comment:
  *      *