简体   繁体   English

如何从包含 Tabcontrol 的窗口中获取所有子项及其值

[英]How to get all children and their values from a Window containing Tabcontrol

EDIT编辑

Straightforward question直截了当的问题

I have been trying for the past 2 days I could find a way to fetch all the children along with the data from a TabControl which has multiple TabItems in it.在过去的 2 天里,我一直在尝试找到一种方法来获取所有子项以及来自其中包含多个 TabItems 的 TabControl 的数据。 it looks like this看起来像这样

在此处输入图像描述

The TABULAR TabControl has three TabItems (TEMPERATURE, TEMPERATURE1, AND PRESSURE) each TabItem contains textboxes and sliders. TABULAR TabControl 具有三个 TabItem(TEMPERATURE、TEMPERATURE1 和 PRESSURE),每个 TabItem 都包含文本框和滑块。 I want to loop through TabItems fetching all the textbox values and slider values.我想遍历 TabItems 以获取所有文本框值和滑块值。

I have tried the following methods but I was only able to see the data in properties when I add the variables to the watch window in debug mode.我尝试了以下方法,但在调试模式下将变量添加到监视窗口时,我只能看到属性中的数据。

METHODS I'VE TRIED我试过的方法

int tabular_items = TabularJsonEditor.Items.Count;
                sock.sendData(tabular_items.ToString());
                foreach(var rh in TabularJsonEditor.Items.SourceCollection)
                {
                    string h = rh.ToString();
                    var coll = TabularJsonEditor.SelectedContent;
                    
                }
                var iEnumeratorOftoBeIterated = TabularJsonEditor.Items.SourceCollection.GetEnumerator();
                while (iEnumeratorOftoBeIterated.MoveNext())
                {
                    Console.WriteLine($"The current value is: {iEnumeratorOftoBeIterated.Current}");
                    var curr = iEnumeratorOftoBeIterated.Current;
                    //var res = LogicalTreeHelper.GetChildren(curr);
                    var rest = ListBindingHelper.GetList(curr);
                    var temp = GetVisualChild(0);
                    
                }

WATCH WINDOW观察窗

在此处输入图像描述

use VisualTreeHelper to get child controls, and test type of child使用VisualTreeHelper获取子控件,并测试子控件的类型

static public void EnumVisual(Visual myVisual)
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
    {
        // Retrieve child visual at specified index value.
        Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);

        if (childVisual is Slider slider)
            Debug.Print(slider.Value);

        // Enumerate children of the child visual object.
        EnumVisual(childVisual);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM