I\'m trying to create a custom control derived from ItemsControl
. The ItemsControl
is initialized with items, but they are not shown.
t
You need to set the ItemsSource. So, for example, you could add ItemsSource = Checkers;
below the last Checkers Add line. Even though you're trying to set the ItemsSource to Checkers in the style, I think it would be easier if you set in the control class. Just my two cents, though.
Here's an example of the PipeControl class:
public class PipeControl : ItemsControl
{
public ObservableCollection Checkers { get; set; }
static PipeControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PipeControl), new FrameworkPropertyMetadata(typeof(PipeControl)));
}
public PipeControl()
{
Checkers = new ObservableCollection();
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
ItemsSource = Checkers;
}
}
You also need an ItemsPresenter in your ControlTemplate and your Ellipse needs a width and height. Here's an updated style for you: