【发布时间】:2011-05-20 07:10:30
【问题描述】:
我绝不是 WPF 方面的专家,所以这可能很简单。我正在尝试将列表绑定到组合框。它在代码中有效,在 xaml 中无效。如果我从构造函数中删除 ItemsSource,它就不起作用,这就是我所知道的。我以为我在 xaml 中有等价物,但显然不是。
xaml:
<ComboBox Height="23"
HorizontalAlignment="Left"
Margin="146,76,0,0"
Name="comboBox1"
VerticalAlignment="Top"
Width="120"
ItemsSource="{Binding AvailableActions}"
DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedValue="Replace" />
构造函数:
public MainWindow()
{
_availableActions = new List<IMapperAction>
{
new ReplaceAction(),
new CollapseAction(),
new NewBasedOnAction()
};
InitializeComponent();
Loaded += OnWindowLoaded;
comboBox1.ItemsSource = AvailableActions;
}
【问题讨论】: