Selectionchanged event firing for every row
I am using a cascading comboboxes inside datagrid.I am able to get the datas based on selectionchanged but that event is firing for every row. Here is my code:
<sdk:datagridtemplatecolumn header="Category" width="110"> <sdk:datagridtemplatecolumn.celltemplate> <datatemplate> <combobox foreground="Black" height="30" isenabled="{Binding Source={StaticResource EffortViewModel}, Path=ComboBoxStatus}" itemssource="{Binding Source={StaticResource EffortViewModel},Path=ProjTypeTaskCtry}" displaymemberpath="TaskCtgyName" selectedvaluepath="TaskCtgy_FK" selectedvalue="{Binding Source={StaticResource EffortViewModel}, Path=TaskCtgy_FKField,Mode=TwoWay}" /> </datatemplate> </sdk:datagridtemplatecolumn.celltemplate> </sdk:datagridtemplatecolumn> <sdk:datagridtemplatecolumn header="SubCategory" width="110"> <sdk:datagridtemplatecolumn.celltemplate> <datatemplate> <combobox foreground="Black" height="30" isenabled="{Binding Source={StaticResource EffortViewModel}, Path=ComboBoxStatus}" itemssource="{Binding Source={StaticResource EffortViewModel},Path=SubCtry,Mode=OneWay}" displaymemberpath="TaskSubCtgyName" selectedvaluepath="{Binding TaskSubCtgy_PK, Mode=TwoWay}" selectedvalue="{Binding TaskSubCtgy_FKField,Mode=OneTime}" selectedindex="{Binding TaskSubCtgy_FKField}" /> </datatemplate> </sdk:datagridtemplatecolumn.celltemplate> </sdk:datagridtemplatecolumn> Answers & Comments...
Answer: 1
Answer: 1
I had the same problem in Silverlight MVVM. I found a solution for this from somewhere. Hope this will help you.
namespace Test { public class ComboBoxSelectionChange : TriggerAction<DependencyObject> { public ComboBoxSelectionChange() { } public ComboBox DayComboBox { get { return (ComboBox)GetValue(DayComboBoxProperty); } set { SetValue(DayComboBoxProperty, value); } } public static readonly DependencyProperty DayComboBoxProperty = DependencyProperty.Register("DayComboBox", typeof(ComboBox), typeof(ComboBoxSelectionChange), new PropertyMetadata(null, OnDayComboBoxPropertyChanged)); private static void OnDayComboBoxPropertyChanged(DependencyObjectd, DependencyPropertyChangedEventArgs e) { var source = d as ComboBoxSelectionChange; if (source != null) { var value = (ComboBox)e.NewValue; } } protected override void Invoke(object o) { if (this.DayComboBox != null) { //this method will execute when the selection is changed } } } } Use the Test namespace in Usercontrol assembly
xmlns:Common="clr-namespace:Test" <UserControl.Resources> <Common:ComboBoxSelectionChange x:Name="ComboBoxItem"/> </UserControl.Resources> <DataTemplate x:Key="EditMondayDataTemplate"> <ComboBox x:Name="cmbMonday" Height="26" Margin="3" ItemsSource="{Binding Monday,Mode=OneTime}" DisplayMemberPath="displayText" SelectedItem="{Binding Path=MonSelected,Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="80"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <Common:ComboBoxSelectionChange DayComboBox="{Binding ElementName=cmbMonday}" TextParam="Monday"/> </i:EventTrigger> </i:Interaction.Triggers> </ComboBox> </DataTemplate> by : Sameerahttp://stackoverflow.com/users/1592350
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog