[WPF]自定义控件中如果想要自定义集合属性该怎么办?
自己继承Window写了一个自定义的窗口,然后想要管理窗口最上方的菜单栏,这样就需要一个集合来存储菜单项。之前仅仅接触过类似Menu此类的控件,它们继承了ItemsControl,拥有Items属性,所以我也想要自定义一个类似Items的属性,但是不知道该怎么初始化它。有没有人做过类似的功能,求指教!还请告诉我如何在模版中绑定此元素,谢谢!
public ItemCollection TopBarMenuItem
{
get { return (ItemCollection)GetValue(TopBarMenuItemProperty); }
set { SetValue(TopBarMenuItemProperty, value); }
}
public static readonly DependencyProperty TopBarMenuItemProperty =
DependencyProperty.Register(nameof(TopBarMenuItem), typeof(ItemCollection), _ownerType);