简体   繁体   English

如何从StackPanel WPF上以编程方式添加的UC中获取价值

[英]How to get value from programmatically added UC on StackPanel WPF

SO here is my UC 所以这是我的UC

 public partial class ChartDialogView : UserControl
    {
      public long Value
        {
         get
           {
              return TextBox1.Content;
           }
        }
        public ChartDialogView()
        {
            InitializeComponent();
        }
    }

And on main form i add some this UC items 在主表单上,我添加一些此UC项目

ChartDialogView uc = new ChartDialogView();
            ChartList.Children.Add(uc);

So question is how to get value of second(for example) added item? 那么问题是如何获得第二(例如)添加项目的价值? this is my XAML(maybe it helps) 这是我的XAML(也许有帮助)

            <ScrollViewer Margin="44,40,0,11"
                          HorizontalAlignment="Left"
                          HorizontalScrollBarVisibility="Hidden"
                          VerticalScrollBarVisibility="Hidden"
                          Width="257"
                          Foreground="{x:Null}">
                <StackPanel x:Name="ChartList">
                    <StackPanel.ScrollOwner>
                        <ScrollViewer CanContentScroll="True" />
                    </StackPanel.ScrollOwner>
                </StackPanel>
            </ScrollViewer>

All of that look like here 所有这些看起来像这里

So i found the way if some one need 所以我找到了办法,如果有人需要

foreach (ChartDialogView setInformation in ChartList.Children.OfType<ChartDialogView>())
            {
                string txt1 = setInformation.Name.Content.ToString() ;
                MessageBox.Show(txt1);
            }

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

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