Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.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
C# 列表框c(windows Phone 8)内的访问控制_C#_.net_Xaml_Windows Phone 8 - Fatal编程技术网

C# 列表框c(windows Phone 8)内的访问控制

C# 列表框c(windows Phone 8)内的访问控制,c#,.net,xaml,windows-phone-8,C#,.net,Xaml,Windows Phone 8,无法工作,因为它们位于listbox的数据模板内 我遇到了可视化的子树方法和其他一些例子。我找不到太多的信息 请帮助我了解此…以下方法查找当前选定的列表框项: accessing textblock string a =txtbindprice.text 更新 您可以向列表框中添加SelectionChanged事件,如下所示: ListBoxItem item = FindSelectedListBoxItem(this); TextBlock txtPrice = FindChil

无法工作,因为它们位于listbox的数据模板内

我遇到了可视化的子树方法和其他一些例子。我找不到太多的信息


请帮助我了解此…

以下方法查找当前选定的列表框项:

accessing textblock 
  string  a =txtbindprice.text
更新

您可以向列表框中添加SelectionChanged事件,如下所示:

ListBoxItem item = FindSelectedListBoxItem(this);
TextBlock txtPrice = FindChildControl<TextBlock>(item , "txtbindprice") as TextBlock;
string a = txtPrice.Text;

我正在寻找一个程序,它可以获取列表框中所有文本块的值……我在列表框中有100多个索引可供选择……但您不必从txtbindprice.text获取它。如果您的ListBox有一个ItemsSource,您可以通过一个迭代100次的循环从该ItemsSource获取每个_价格。我的ListBox中的项目索引将有所不同,因为我正在为ListBox实现搜索功能。。所以有时候项目源不匹配..我在列表框中有一堆项目。。。。它正在检索不匹配的数据。。如何根据selecteditem Index获得准确的数据您的意思是什么?此内部FindSelectedListBoxItem这是主窗口的一个实例,或者如果您在selectionChanged事件中使用此方法,则可以使用ListBoxsender。为什么可视化子树方法不适用于您?你试过了吗?根据我的要求,哪一个更好?我会根据这些更新我的答案。谢谢。请具体一点。这对我的学习目的很有用。。
    private ListBoxItem FindSelectedListBoxItem(DependencyObject control)
    {
        int childNumber = VisualTreeHelper.GetChildrenCount(control);
        for (int i = 0; i < childNumber; i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(control, i);
            FrameworkElement fe = child as FrameworkElement;
            // Not a framework element or is null
            if (fe == null) return null;

            if (child is ListBoxItem && ((ListBoxItem)child).IsSelected)
            {
                // Found the control so return
                return (ListBoxItem)child;
            }

            else
            {
                // Not found it - search children
                ListBoxItem nextLevel = FindSelectedListBoxItem(child);
                if (nextLevel != null)
                    return nextLevel;
            }
        }
        return null;
    }
private DependencyObject FindChildControl<T>(DependencyObject control, string ctrlName)
{
    int childNumber = VisualTreeHelper.GetChildrenCount(control);
    for (int i = 0; i < childNumber; i++)
    {
        DependencyObject child = VisualTreeHelper.GetChild(control, i);
        FrameworkElement fe = child as FrameworkElement;
        // Not a framework element or is null
        if (fe == null) return null;

        if (child is T && fe.Name == ctrlName)
        {
            // Found the control so return
            return child;
        }
        else
        {
            // Not found it - search children
            DependencyObject nextLevel = FindChildControl<T>(child, ctrlName);
            if (nextLevel != null)
                return nextLevel;
        }
    }
    return null;
}
ListBoxItem item = FindSelectedListBoxItem(this);
TextBlock txtPrice = FindChildControl<TextBlock>(item , "txtbindprice") as TextBlock;
string a = txtPrice.Text;
 <ListBox Height="Auto" Name="lstbxmanual" SelectionChanged="OnSelectionChanged">
</ListBox>
public void OnSelectionChanged(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem item = FindSelectedListBoxItem((ListBox(sender)));
    TextBlock txtPrice = FindChildControl<TextBlock>(item , "txtbindprice") as TextBlock;
    string a = txtPrice.Text;
}