October 14th, 2010, 09:19 PM
WPF Custom Control ContentControl for a label with other items
apologize if this question seems silly or has already been asked somewhere else, but I cannot seem to find the solution.
I have a custom WPF user control 'DotControl' that consists of a dynamic number of circles (like a multiple choice question), those circles are added programatically when the DotCount property is set. This is have working wonderfully.
What i cannot seem to do is, i would like to also have a Label (or text block I'm not really sure of the difference) built into this control (so that I do not have to add a label on the main window as well).
MyLabelTextHere O O O O O
I cannot seem to make BOTH the text and the circles show up, it seems either one or the other works. Ideally what i would like to be able to do is use the Content property so that I can have my XAML look something like this:
<localotControl Name="MyDotControl" DotCount="5" >MyLabelTextHere</localotControl>
Does anyone know how to accomplish this? Any help or push in the right direction would be greatly appreciated.
<StackPanel Name="DotPanel" Orientation="Horizontal" Width="Auto" Height="Auto">
public partial class DotControl : UserControl
private int _dotCount;
private List<Ellipse> _dots;
_dots = new List<Ellipse>();
public int DotCount
_dotCount = value;
private void refreshDots()
for (int i = 0; i < _dotCount; i++)
Ellipse e = new Ellipse();
e.Height = 15;
e.Width = 15;
e.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
e.Fill = Brushes.White;
e.Stroke = Brushes.Black;
e.StrokeThickness = 1.0f;
e.Margin = new Thickness(5, 0, 0, 0);
e.MouseUp += new MouseButtonEventHandler(dot_MouseUp);
private void clearDots()
foreach (Ellipse e in _dots)
private void addDot(Ellipse e)
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!