Click here to Skip to main content
11,646,620 members (77,850 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WPF

I am developing an application with WPF that uses a 3rd party software. I`m struggling to make some label generated dynamically from an wpf user control and it seems that i`m not able to succeed.

Well, lets start.

I have an windows form that host an wpf user control. In that control i want to generate those labels and populate another windows form that pops up after the labels insertion.

The code looks something like this:

public void GetPropertyInfo(IvcComponent comp)
   int nr = comp.getPropertyCount;
   PropertyControl pc = new PropertyControl(); // this is the new win form
   for(int i=0;i<nr;i++)
      Label x = new  Label();
      x.Name = comp.getPropertyName(i);
      x.Content = comp.getPropertyName(i);
      // here i should add the label to the PropertyControl form
Posted 8-Jan-13 5:49am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

To start with, it's good to understand WPF content model: Question about MCTS exam[^].

First of all, you need to have some UIElement in your control which itself can have children, so you could add your label to it. Look at the abstract class System.Windows.Controls.Panel:[^],[^].

You need to choose appropriate non-abstract derived class, to have a panel you can insert in your control:[^].

Typically, it will be Grid or DockPanel, and you will insert your label like myPanel.Children.Add(x). Location/layout and other properties of this parent-child relationships depends on the concrete panel class which you will be able to find in its documentation, but it's good to understand the functionality and the use of dependency properties:[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 510
1 Sergey Alexandrovich Kryukov 503
2 OriginalGriff 458
3 CPallini 329
4 Afzaal Ahmad Zeeshan 300
0 OriginalGriff 1,253
1 994
2 DamithSL 896
3 Sergey Alexandrovich Kryukov 833
4 CPallini 720

Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100