0

我有一个枢轴,其中枢轴填充有用户控件(每个都有一个文本框(元素的标题)和一个文本框(元素的值)),更新用户控件后,我必须获取新值并更新我的数据库,例如我手动导航并从用户控件的 rextBox 中获取值,我知道这不是最好的方法,这就是为什么我要寻求帮助!这是一个例子:

  for (int i = 0; i < mypivot.Items.Count; i++)
   {
       PivotItem mypivot_Item_i = mypivot.Items[i] as PivotItem;
               grid = (Grid)(((ScrollViewer)(((Grid (pvt_Item_i.Content)).Children.ElementAt(0))).Content);
                for (int j = 0; j < grid.Children.Count; j++)
                {
                    string type = grid.Children.ElementAt(j).GetType().ToString();
                    if(type.Equals( "MyUserControl")
                                // some code

                }
    }
4

2 回答 2

0
<phone:Pivot Name="pvt" Visibility="Collapsed">
        <phone:Pivot.Title >
            <StackPanel Width="460" Background="{StaticResource PhoneChromeBrush}">
                <TextBlock Text="{Binding FileTitle}" FontSize="30" Height="45" VerticalAlignment="Center" HorizontalAlignment="Center"   />
            </StackPanel>
        </phone:Pivot.Title>
于 2013-09-25T14:29:15.423 回答
0
    public void BuildPage(Pivot mypivot)
    {

        foreach (Tab tab_i in tabs)
        {
            List<Section> sectionsOfTab_i = sectionsByTab[tab_i];

            Grid grid = new Grid();
            int numRow = 0;
            foreach (Section section_i in sectionsOfTab_i) // ici on a toute les sections 
            {

                string sectionName = section_i.name;
                if (!sectionName.Equals(""))
                {
                    grid.RowDefinitions.Add(new RowDefinition() { Height = System.Windows.GridLength.Auto });
                    var textBlock = new TextBlock() { Text = sectionName, FontSize = 30 };
                    Grid.SetRow(textBlock, numRow);
                    grid.Children.Add(textBlock);
                    numRow++;

                    grid.RowDefinitions.Add(new RowDefinition() { Height = System.Windows.GridLength.Auto });
                    var border = new Border() { BorderBrush = new SolidColorBrush(Colors.DarkGray), Height = 1, Width = 450, BorderThickness = new Thickness(0.5) };
                    Grid.SetRow(border, numRow);
                    grid.Children.Add(border);
                    numRow++;
                }
                foreach (Control control_i in controlsOfAllSections[section_i])
                {
                    grid.RowDefinitions.Add(new RowDefinition() { Height = System.Windows.GridLength.Auto });
                    Grid.SetRow(control_i, numRow);
                    numRow++;
                    grid.Children.Add(control_i);
                }
            }
            PivotItem  mypivot_item = new PivotItem() { Header = new TextBlock() { Text = tab_i.name, FontSize = 30, Margin = new Thickness(0, 10, 0, 0) } };
            Grid pvtGrid = new Grid();
            ScrollViewer sv = new ScrollViewer();
            pvtGrid.Children.Add(sv);
            sv.Content = grid;
            pvt_item.Content = pvtGrid;
            mypivot.Items.Add( mypivot_item);
        }

    }
于 2013-09-25T14:32:39.890 回答