我正在尝试创建一个从ItemsControl
. 用ItemsControl
项目初始化,但未显示。
项目控制:
public class PipeControl : ItemsControl
{
static PipeControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PipeControl), new FrameworkPropertyMetadata(typeof(PipeControl)));
}
public PipeControl()
{
Checkers = new ObservableCollection<Checker>();
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
Checkers.Add(new Checker());
}
public ObservableCollection<Checker> Checkers
{
get;
set;
}
}
主题资源字典:Generic.xaml
<Style TargetType="{x:Type local:PipeControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PipeControl}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type local:Checker}">
<Ellipse Fill="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsSource" Value="{Binding Checkers,RelativeSource={RelativeSource Self}}"/>
<!-- Just a Precaution its the default panel any ways -->
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
任何想法为什么不显示这些项目?