I have combo as
<ig:XamComboEditor Name="YComboEditor" ItemsSource="{Binding Path=YearsData}" DisplayMemberPath="SomeYear" SelectionChanged="YComboEditor_SelectionChanged" SelectedItem="{Binding SomeYear,Mode=TwoWay,Converter={StaticResource YearConverter}}">
</ig:XamComboEditor>
This is populated correctly
I have IvalueConverter which checkes for the year and then should return current year as selected
For some reason the IValueconverter is not triggered
Any ideas?
Hi,
in order for the ValueConverter to be triggered a valid binding should be used so the ValueConverter will have something to convert from/to. Is "SomeYear" valid binding target in your view model?
Looking at your xaml I am get the impression(the path for your SelectedItem binding is the same as the DisplayMemeberPath string) that you are trying to bind to a property of an ItemSource's item. Generally you should bind SelectedItem to a valid binding target.
You could check this sample which is showing how xamComboEditor is used with value converter in SelectedItem binding.
Regards
<SomeYear> is the fieldname, Its valid binding target
The DisplayMemeberpath and selected item is same
I do not have the combo in grid
Its just the combo
The Years range from 1980-2014
I want the current year to be selected as default in the combo editor any pointers?
why do you need to set default selected value through a ValueConverter? Can't you set the current year to <SomeYear>property while creating your business object?
Hint that might be of help: when using SelectedItem property in binding you should ensure that SelectedItem's value can be found in XamComboEdiotr's ItemsSource. If you try to set SelectedItem to something that cannot be found in ItemsSource nothing will be selected
Right now I have the same approach as you mentioned
could you provide simplified sample solution illustrating the issue you are experiencing ?
assuming that this code is placed in some kind of an Initialization method this should set the selected value to the current year.
Right now the solution i have is
var collection = ComboEditor1.ItemsSource.Cast<YearData>().ToList(); var value = collection.Where(item => item.YearXX == DateTime.Today.Year).FirstOrDefault(); ComboEditor1.SelectedItem = value;
Is this correct approach?