multiselection combobox in wpf using mvvm
I am using WPF MVVM model in my project using C#.Net.
I am trying to bind data from DB to multiselection combobox using MVVM.
Data binded in Itemsource collection. But not displayed in multiselection combobox.
Also based on the selection data should store in DB (SQL Server). We are using entity framework to save data.
Herewith I have attacehd my code. Please guide.
I have attached my XAML and ViewModel Code for your reference.
XAML Code:
==========
<ComboBox Name="cmbDlDashletName" Style="{StaticResource VisaBirdComboBoxStyle}" SelectedValuePath="DashletName" SelectedValue="{Binding DashletName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True,NotifyOnValidationError=True}" ItemsSource="{Binding WidgetCollectionProperty}" IsEnabled="{Binding Path=PropertyStates[readOnly].IsEditable}" Height="25" Width="355" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionChangedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBox.ItemTemplate>
<DataTemplate>
<!--<StackPanel Orientation="Horizontal">-->
<CheckBox Name="chkDashlet" Content="{Binding Path=DashletName}" IsChecked="{Binding DashletAccess, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBoxItem}}" >
<!--<TextBlock Text="{Binding DashletName}" VerticalAlignment="Center"/>-->
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding CheckboxCheckedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!--</StackPanel>-->
</CheckBox>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
View Model:
==========
WindowElement winElement = GetWindowElement.GetElement(Collection.DashletFormName);
if (DataValidator.IsValid(winElement))
{
if (this.ViewMode == ViewModeType.Add)
{
bool doesExistAlready = DashletCollectionProperty.Count(x => x.DashletName == DashletName && x.DashletUserId == DashletUserId) > 0;
if (!doesExistAlready)
{
foreach (var Values in DashletCollectionProperty)
{
Values.UserName = UserCollection.Where(x => x.User_UserId == DashletUserId).Select(a => a.User_UserLoginId).Single(); //UserName;
Values.DashletName = DashletName;
Values.CreatedBy = LoginUserDetails.UserId;
Values.ModifiedUserId = LoginUserDetails.UserId;
Values.DateEntered = DateTime.Now;
Values.DateModified = DateTime.Now;
Values.DateModifiedUtc = DateTime.Now;
Values.DashletUserId = DashletUserId;
DashletAccess = false;
if (DashletAccess == false)
{
User_Dashlet_Type = User_Dashlet_Type + "0,";
DashletUserId = DashletUserId;
}
else
{
User_Dashlet_Type = User_Dashlet_Type + "1,";
DashletUserId = DashletUserId;
}
User_Dashlet_Type = User_Dashlet_Type.Remove(User_Dashlet_Type.Length - 1);
DashletUserId = DashletUserId.Remove(DashletUserId.Length - 1);
Values.User_Dashlet_Type = User_Dashlet_Type;
DashletCollection.Add(Values);
ResultInfo = VisaBirdRestMethods.VisaBirdSendData("CRUD_Operations_Dashlet_Rest/Insert" + DEModeEnum.Insert, Values, typeof(DEDashlet)) as DEErrorProvider;
if (ResultInfo.ErrorResult)
{
RestGetDashletList();
VisaBirdMessage.showMessage(Collection.DashletData + ContentResource["DetailsView_SaveSuccess_Validation"].ToString(), ContentResource["DetailsView_Information"].ToString(), DialogButton.Ok, 500);
}
else
{
VisaBirdMessage.showMessage(Collection.DashletData + ContentResource["DetailsView_SaveError_Validation"].ToString(), ContentResource["DetailsView_Information"].ToString(), DialogButton.Ok, 500);
}
Please advise.