我想用一些功能扩展默认下拉菜单。自定义下拉菜单的行为应该类似于.xaml
文件中的默认下拉菜单,因此应该可以向其中添加项目。
不幸的是,它似乎不像在 WPF 中那样工作。这就是我的方法:
MainWindow.xaml:(添加命名空间)
<local:myCustomDropDown>
<DropDownItem>1</DropDownItem>
<DropDownItem>2</DropDownItem>
</local:myCustomDropDown>
myCustomDropDown.xaml:
<DropDown xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaApplication2.myCustomDropDown">
</DropDown>
后面的代码:
public class myCustomDropDown : DropDown
{
public myCustomDropDown()
{
this.InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
这似乎编译没有错误或警告,但控件不显示。