从组合框(级联)mvvm中获取选定的值

时间:2015-06-23 05:00:26

标签: wpf vb.net mvvm combobox

我的视图中有3个级联组合框,2个绑定到ObservableCollection,1个(第一个)有自己的项目。我想获取每个的选定值以将其保存到数据库中。我试图用SelectedItem做这个,但我得到的是表的字符串名称。

你能给我一些建议吗?

视图模型:

Public Property First() As ObservableCollection(Of tbl_Activities_First)
    Get
        Return _First
    End Get
    Set(value As ObservableCollection(Of tbl_Activities_First))
        _First = value
    End Set
End Property

Public Property Second() As ObservableCollection(Of tbl_Activities_Second)
    Get
        Return _Second
    End Get
    Set(value As ObservableCollection(Of tbl_Activities_Second))
        _Second = value
    End Set
End Property

Public Property SelectedFirst() As tbl_Activities_First
    Get
        Return _SelectedFirst
    End Get
    Set(value As tbl_Activities_First)
        _SelectedFirst = value
        RaisePropertyChanged("SelectedFirst")
        If Not IsNothing(_SelectedFirst) Then
            BlockActivity = _SelectedFirst.BlockAct
            _Second.Clear()
            _Second = Me.FillSecondActivity()
            SecondEnabled = True
        Else
            SecondEnabled = False
        End If
        RaisePropertyChanged("Second")
    End Set
End Property


Public Property NonProcessAct() As ObservableCollection(Of tbl_Non_Process)
    Get
        Return _NonProcess
    End Get
    Set(value As ObservableCollection(Of tbl_Non_Process))
        _NonProcess = value
    End Set
End Property

XAML:

                            <ComboBox Controls:TextBoxHelper.Watermark="Please select category..." FontFamily="HP Simplified Light" 
                                      Width="342" Height="27" Controls:TextBoxHelper.ClearTextButton="True" Background="{x:Null}"
                                      SelectedIndex="{Binding EmployeeViewM.ActivityType, Mode=OneWayToSource}" SelectedValuePath="TabIndex" Margin="88,20,84.4,355.4">
                                <ComboBoxItem Content="Process" TabIndex="1"/>
                                <ComboBoxItem Content="Non-Process" TabIndex="2"/>
                                <I:Interaction.Triggers>
                                    <I:EventTrigger EventName="SelectionChanged">
                                        <I:InvokeCommandAction Command="{Binding EmployeeViewM.ExecuteFill, Mode=OneWay}"/>
                                    </I:EventTrigger>
                                </I:Interaction.Triggers>
                            </ComboBox>

                            <ComboBox Controls:TextBoxHelper.Watermark="Please select activity..." Controls:TextBoxHelper.ClearTextButton="True"
                                      FontFamily="HP Simplified Light" Height="27" Width="342" Background="{x:Null}" Margin="88,52,84.4,323.4">
                                <ComboBox.Style>
                                    <Style TargetType="ComboBox" BasedOn="{StaticResource MetroComboBox}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding EmployeeViewM.ActivityType, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="0">
                                                <Setter Property="ItemsSource" Value="{Binding EmployeeViewM.First }" />
                                                <Setter Property="SelectedItem" Value="{Binding EmployeeViewM.SelectedFirst}"/>
                                                <Setter Property="DisplayMemberPath" Value="FirstActivity"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding EmployeeViewM.ActivityType, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="1">
                                                <Setter Property="ItemsSource" Value="{Binding EmployeeViewM.NonProcessAct }"/>
                                                <Setter Property="DisplayMemberPath" Value="Activity"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </ComboBox.Style>
                            </ComboBox>

                            <ComboBox Controls:TextBoxHelper.Watermark="Please select second activity... (optional)" Controls:TextBoxHelper.ClearTextButton="True"
                                      FontFamily="HP Simplified Light" Height="27" Width="342" Background="{x:Null}" ItemsSource="{Binding EmployeeViewM.Second}"
                                      DisplayMemberPath="SecondActivity" Margin="88,84,84.4,291.4" 
                                      IsEnabled="{Binding EmployeeViewM.SecondEnabled, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}"/>

0 个答案:

没有答案