Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 8 WP8当包含的文本框获得焦点时选择ListBoxItem_Windows Phone 8_Listbox_Focus_Selecteditem - Fatal编程技术网

Windows phone 8 WP8当包含的文本框获得焦点时选择ListBoxItem

Windows phone 8 WP8当包含的文本框获得焦点时选择ListBoxItem,windows-phone-8,listbox,focus,selecteditem,Windows Phone 8,Listbox,Focus,Selecteditem,在Windows Phone 8上,我有一个listbox,每个ListboxItem的数据模板都包含文本框(以及复选框等) 现在,当用户单击文本框(复选框等)时,它会获得焦点,但列表框的SelectedItem属性不会改变。我需要知道用户当前正在编辑列表中的哪个项目,并且我使用MVVM模式,因此我绑定SelectedItem 对于WPF,我发现了几种方法,但它们都不适用于WP8,主要是因为WP8上没有触发器 感谢您的帮助使用TextBox的GotFocus事件获取ListBoxItem pri

在Windows Phone 8上,我有一个listbox,每个ListboxItem的数据模板都包含文本框(以及复选框等)

现在,当用户单击文本框(复选框等)时,它会获得焦点,但列表框的SelectedItem属性不会改变。我需要知道用户当前正在编辑列表中的哪个项目,并且我使用MVVM模式,因此我绑定SelectedItem

对于WPF,我发现了几种方法,但它们都不适用于WP8,主要是因为WP8上没有触发器


感谢您的帮助

使用TextBox的GotFocus事件获取ListBoxItem

private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
    ListBoxItem itemSelected = sender as ListBoxItem;
    listBox.SelectedItem = itemSelected;
    // You can also get underlying data context of MVVM by
    // MyDataContextClass selected = itemSelected.DataContext as MyDataContextClass;
    // where MyDataContextClass is the class with which you are binding ListBoxItem
}

你想在这里实现什么?当文本框聚焦为SelectedItem时,是否获取实际文本框?