[WPF] ComboBox: error multiConverter and Selected Item
Hi,
in my datagrid I insert a TextBlock and ComboBox for edit cell.
When I click in the cell for edit and I select an item of combox:
1) the item selected is not shown in cell of DataGrid.
2) my Convert is called two times.
Why?
XAML
<DataGridTemplateColumn Header="{StaticResource datagridDay}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Day, Mode=TwoWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Name="dgCmbDay" DataContext="{Binding}">
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource DateNumNameConverter}" >
<MultiBinding.Bindings>
<Binding ElementName="dgPlan" Path="CurrentItem"/>
<Binding Source="{StaticResource AnalysisPlanViewModel}" Path="ListDayNameOfWeek"/>
<Binding Source="{StaticResource AnalysisPlanViewModel}" Path="ListDayNumOfMonth"/>
<Binding Path="Items"></Binding>
</MultiBinding.Bindings>
</MultiBinding>
</ComboBox.ItemsSource>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
My Converter:
public class DayNumName : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null || values.Length < 4)
return null;
AnalysisPlanItemExt analisysPlanItem = (AnalysisPlanItemExt)values[0];
List<string> listDayOfWeek = (List<string>)values[1];
List<string> listDayNumOfMonth = (List<string>)values[2];
if (analisysPlanItem.Type != null)
{
//Day of Weeks
if (analisysPlanItem.Type.Value.Equals(Definition.SchedTypeEnum.DayOfWeek))
return listDayOfWeek;
if (analisysPlanItem.Type.Value.Equals(Definition.SchedTypeEnum.DayOfMonth))
return listDayNumOfMonth;
}
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new System.NotImplementedException();
}
}
Thanks!