1.I want to refresh the comboboxitem when i dropdown the combobox, so i add eventtrigger to excute dropdownopen command,here is the code of xaml,vm,model (1)xaml enter image description here
<DataGrid ItemsSource="{Binding BSFinalWorkday}" AutoGenerateColumns="False" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Shop" Binding="{Binding WorkshopID}" IsReadOnly="True"/>
<!--M1-->
<DataGridTemplateColumn Header="M1">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="m1combox" SelectedValue="{Binding Jan,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.SingleBSShift}"
SelectedValuePath="TotalWorkday" DisplayMemberPath="TotalWorkday" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="DropDownOpened">
<i:InvokeCommandAction
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.InitSingleBSShiftCmdString}" >
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{ StaticResource ResourceKey=objectConverter}" Mode="TwoWay">
<MultiBinding.Bindings>
<Binding Path="WorkshopID"/>
<Binding Path="M1"/>
</MultiBinding.Bindings>
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
(2)viewmodel`private ObservableCollection singleBSShift;
public ObservableCollection<BSAvailableShiftWorkday> SingleBSShift
{
get { return singleBSShift; }
set { singleBSShift = value; RaisePropertyChanged(); }
}
public DelegateCommand<object> InitSingleBSShiftCmdString { get; set; }
public void InitSingleBSShiftMethodString(object obj)
{
object[] multiObj = obj as object[];
string wID = multiObj[0] as String;
string month = multiObj[1] as String;
Console.WriteLine("Hi");
Console.WriteLine(wID);
Console.WriteLine(month);
if (BSAvailableShift != null)
{
SingleBSShift.Clear();
var res = BSAvailableShift.Where(p => p.WorkshopID == wID && p.Month== month).Select(p => p);
foreach (var b in res) { SingleBSShift.Add(b); }
}
}`
(3)model
public class BSAvailableShiftWorkday : BindableBase { private string workshopID;
public string WorkshopID
{
get { return workshopID; }
set { workshopID = value; RaisePropertyChanged(); }
}
private string month;
public string Month
{
get { return month; }
set { month = value; RaisePropertyChanged(); }
}
private string totalWorkday;
public string TotalWorkday
{
get { return totalWorkday; }
set { totalWorkday = value; RaisePropertyChanged(); }
}
2.When i selected row's combobox, it truly shows the selectedvalue,but when i click next row's combobox, the above selectedvalue disappear enter image description here