如何将SelectedItem(从ListBox)绑定到变量?

Jos*_*nel 1 c# silverlight windows-phone-7

我正在研究我的第一个WP7应用程序,这个问题让我有点头疼.

我有一个像这样定义的ListBox

    <ListBox Grid.Row="1" ItemsSource="{Binding MyItemList}" SelectedItem="{Binding MySelectedItem}">
        <ListBox.ItemTemplate>
            <DataTemplate >
                <StackPanel>
                    <TextBlock Text="{Binding Name}" FontSize="35" />
                    <TextBlock Text="{Binding Details}" FontSize="15"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
Run Code Online (Sandbox Code Playgroud)

绑定ItemsSource工作正常,但选择项目时MySelectedItem-Property不会更新.这个功能没有实现(比如在WPF中)或我只是在做什么?:-)

ind*_*moz 6

只需使用 -

SelectedItem="{Binding MySelectedItem, Mode=TwoWay}" 它应该没问题.