在Silverlight中,如何将ControlTemplate中ComboBox的SelectedItem绑定到ViewModel属性

时间:2013-05-23 14:19:55

标签: silverlight mvvm binding controltemplate selecteditem

我有ComboBox的代码,可以将SelectedItem绑定到ViewModel中的属性:

<dxe:ComboBoxEdit x:Name="luTeacher"
    Margin="0,5,0,0"
    AutoComplete="True"
    ItemsSource="{Binding ddsTeachers.Data}"
    SelectedItem="{Binding SelectedTeacher, Mode=TwoWay}"
    ValueMember="UserId"
    DisplayMember="FullName"/>

但是当我尝试将其复制并在Combobox中的ControlTemplate上使用时,它无效:

<dxe:ComboBoxEdit
    HorizontalAlignment="Left"
    Grid.Column="1"
    Grid.Row="0"
    Margin="0,0,0,4"
    VerticalAlignment="Top"
    Width="150"
    AutoComplete="True"
    ItemsSource="{Binding Path=ddsViewTeacher.Data, Source={StaticResource vm}}"
    SelectedItem="{Binding SelectedNewTeacher,
                           Mode=TwoWay, Source={StaticResource vm}}"
    DisplayMember="FullName"
    ValueMember="UserId"/>

ItemsSource有效,但SelectedItem未更新。有什么想法吗?

0 个答案:

没有答案