Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
870
No Selected Value?
posted

It is hard to believe that you guys would make the same mistake as Microsoft, and not include a SelectedValue dependency property on your XamComboBoxEditor.  Will this be included in a service release or is it planned for a future implementation?

Parents Reply
  • 40030
    Offline posted in reply to Brian Lagunas

    Hi, 

    So what you're saying is pretty much described in the following blog:

    http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-selectedvalue.aspx

    In the article, he demonstrates how this would be done with a SelectedValue and instead of States he uses Countries.

    Now, using the code from the article, you can modify it slightly, and achieve the same thing without a SelectedValue property:

    First you write an IValueConverter:

     public class MyValueConverter : IValueConverter

        {

     

            #region IValueConverter Members

     

            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

            {

                CountryLookup cl = parameter as CountryLookup;

     

                if (cl != null && value != null)

                {

                    List<Country> countries = cl.Countries;

                    var val =countries.FirstOrDefault(o=> o.Id == (int)value);

                    return val;

                }

                return value;

            }

     

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

            {

                Country c = value as Country;

                if(c != null)

                    return c.Id;

                return value;

            }

     

            #endregion

        }

    Then, you replace his ComboBox with our xamWebComboEditor:

     <ig:XamWebComboEditor  

                                Margin="5"  

                                ItemsSource="{Binding Source={StaticResource countryLookup},Path=Countries}"  

                                DisplayMemberPath="CountryName"   

                                SelectedItem="{Binding CountryId, Mode=TwoWay, Converter={StaticResource mvc}, ConverterParameter={StaticResource countryLookup}}"

                                />

    And you'll have the same results. 

    Does this help you?

    -SteveZ

Children