Hi sivakumarmr10,
How are you adding your controls? If you're using WPF it may be possible to bind a "ContentPresenter" to a List in your "CodeBehind" file or "ViewModel" class, depending on your methodology and then iterate through that list, picking out the control you're looking for.
The list that you create, could be a list of your own predefined type, this type could then have a property such as unique identifier. When iterating through this list, you could retrieve the control that you need depending on that attribute.
You can define the type of control inside a data-template of your newly created type.
<DataTemplate DataType="{x:Type MyClass}">
<Button/>
<<DataTemplate />
Then in your XML file :
<Border BorderThickness="1" Background="White">
<ScrollViewer>
<ItemsControl ItemsSource="{Binding MyClassDP}" />
</ScrollViewer>
</Border>
Depending on the data context of your code behind you may then wish to set a dependency property in either the code behind or a separate class, naive to your .xaml.cs file :
#region MyClassDp
public static readonly DependencyProperty MyClassDpProperty =
DependencyProperty.Register("MyClassDp", typeof(List<MyClass>), typeof(Program),
new FrameworkPropertyMetadata((List<MyClass>)null));
public List<MyClass> MyClassDp
{
get { return (List<MyClass>)GetValue(MyClassDpProperty); }
set { SetValue(MyClassDpProperty, value); }
}
#endregion
I hope this helps, apologies if that's not the approach you're going for. I have given a similar answer to this one elsewhere in relation to WPF data-bindings which might help.
Credit to
DR WPF for DP Auto-Generated Snippet.