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?
I'm trying to use this method to have a XamWebComboEditor attached to a XamWebGrid, but I cannot find the right combination. (Silverlight 3, Infragistics 10.1.20101.1005)
Issues that I am having:
Here is my object, provider, and converter, very similar to example:
public class ValueType
{
public string ValueTypeName { get; set; }
public string ValueTypeID { get; set; }
}
public class ValueTypeList
public ValueTypeList()
valueTypes = new List<ValueType>()
new ValueType() { ValueTypeID = "D", ValueTypeName = "DateTime" },
new ValueType() { ValueTypeID = "I", ValueTypeName = "Integer" },
new ValueType() { ValueTypeID = "F", ValueTypeName = "Decimal" },
new ValueType() { ValueTypeID = "S", ValueTypeName = "String" }
};
public List<ValueType> valueTypes { get; set; }
public class ValueTypeConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
ValueTypeList vtl = parameter as ValueTypeList;
if (vtl != null && value != null)
List<ValueType> valTypes = vtl.valueTypes;
var val = valTypes.FirstOrDefault(o => o.ValueTypeID == (string)value);
return val;
return value;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
ValueType v = value as ValueType;
if (v != null)
return v.ValueTypeID;
Here is the column in my XamWebGrid:
<igGrid:TemplateColumn Key="DefaultValueType" HeaderText="Value Type" Width="Auto">
<igGrid:TemplateColumn.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="DisplayValueType" Text="{Binding DefaultValueType}"/><!--, Converter={StaticResource valueTypeConverter}, ConverterParameter={StaticResource valueType}}" />-->
</DataTemplate>
</igGrid:TemplateColumn.ItemTemplate>
<igGrid:TemplateColumn.EditorTemplate>
<igCombo:XamWebComboEditor x:Name="ValueTypeEditList"
SelectedItem="{Binding ValueTypeID, Mode=TwoWay, Converter={StaticResource valueTypeConverter}, ConverterParameter={StaticResource valueType}}"
DisplayMemberPath="ValueTypeName" ItemsSource="{Binding Source={StaticResource valueType}, Path=valueTypes}" />
</igGrid:TemplateColumn.EditorTemplate>
</igGrid:TemplateColumn>
Notice that I've commented out the Converter details of the TextBlock. When it is commented out, the initial value of the cell upon binding is the ID value (e.g. "D" or "S"). If I include the converter details, the value of the cell just displays the Type of the object -- "Proj.ValueType"
Whenever I change the selected item of the combo, it does not reflect the change in the cell.
*EDIT*
Issue 1 solved by correcting the XamWebComboEditor SelectedItem binding to match the key of the column (DefaultValueType) instead of the ID property (ValueTypeID).
Issue 2 solved by using a different Converter on the TextBlock then on the XamWebComboEditor. The Convert() returns Name property (instead of the object).
I am aware that I could accomplish this with a value converter. I could also extend your control and add the dependencies properties to support my functionality (this is what I did with the Microsoft combo box). I was just bringing to your attention of this short coming with your control. As you will see, Microsoft has fixed this in their combo box in Silverlight 4 and now have a SelectedValue and a SelectedValueMemberPath dependency property. I hope you could add this to your combo box as well.
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
CountryLookup cl = parameter as CountryLookup;
if (cl != null && value != null)
List<Country> countries = cl.Countries;
var val =countries.FirstOrDefault(o=> o.Id == (int)value);
Country c = value as Country;
if(c != null)
return c.Id;
#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
Lets say I have a collection of objects defined as follows:
ObservableCollection<State> states;
public class State
public Guid Id {get;set;}
public string Value {get;set;}
Now I am a customer object that has a property on it call StateId as follows
public class Customer
public Guid StateId {get;set;}
If my ItemsSource to the XamWebComboEditor is a collection of states the SelectedItem will be of type State. So when I am data binding my StateId property of my Customer to the SelectedItem of the ComboBox, it is expecting a type of State and not Guid. So when a new selection is made, a state object is sent to my property's setter not a Guid, and when the combo is created, it will not selected the correct state since it is trying to bind to type State and not Guid.
Basically, this is a very common scenario, especially in web development. In WebForms you have a combo box that displays text, but uses a different value for binding.
I believe you should be able to achieve everything with the SelectedItem property, as a SelectedValue would essentially just be a property that is on the SelectedItem.
Could you explain what your use case is for needing a SelectedValue property? I could probably help you solve your problem. Otherwise, if it's something that really is necessary, we can look into adding as a feature in the future.