TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Roberto Salemi
NA
146
142.1k
[WPF] ComboBox: error multiConverter and Selected Item
Feb 26 2015 9:53 AM
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!
Reply
Answers (
1
)
[WPF] DataGrid: add a new line, what is the best solution?
[WPF] ComboBox and ItemSource: add one empty row