我需要制作一个Usercontrol
并将其添加Window
到我使用它的控件中,因此我在ItemsControl
其中定义了一个,如下所示:
<UserControl x:Class="MySystem.Controls.DropDownPanel"
x:Name="this" ....>
<Grid>
<Popup x:Name="popup" ...>
<Grid>
<ItemsControl ItemsControl.ItemsSource="{Binding ElementName=this, Path=PanelItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</Popup>
</Grid>
而且我还在DependencyProprty
后面的代码中创建了一个(PanelsItem):
public static readonly DependencyProperty PanelItemsProperty = DependencyProperty.Register("PanelItems"
, typeof(ObservableCollection<UIElement>)
, typeof(DropDownPanel));
public ObservableCollection<UIElement> PanelItems
{
get
{
return (ObservableCollection<UIElement>)GetValue(PanelItemsProperty);
}
set
{
SetValue(PanelItemsProperty, value);
}
}
现在我想添加如下控件:
<Windowx:Class="MySystem.UI.View.PeopleView"
...
x:Name="this"
xmlns:controls="clr-namespace:MySystem.Controls;assembly=MySystem.Controls">
<Grid>
<controls:DropDownPanel>
<commonControls:DropDownPanel.PanelItems>
//??How to add controls Here??
</commonControls:DropDownPanel.PanelItems>
</commonControls:DropDownPanel>
</Grid>
</Window>
如果我直接在中添加控件,PanelsItem
我会收到此错误:{“'Collection property 'MySystem.Controls.DropDownPanel'.'PanelItems' is null'”}
有任何想法吗?