Dude -- 一切都可以用 XAML 完成:D
按照 MVVM 方法,我建议您执行以下操作:
1/ 入门:A DockPanel
<DockPanel LastChildFill="True">
<Button DockPanel.Dock="Bottom" />
<ListBox />
</DockPanel>
2/ 将 ListBox 绑定到 ViewModel 中的 ObservableCollection:
<ListBox ItemsSource="{Binding ListElements}" />
在 ViewModel 中:
private ObservableCollection<String> _listElements;
public ObservableCollection<String> ListElements
{
get { return _listElements; }
set { _listElements = value; }
}
3/ 将Button 的内容绑定到预定义的String:
<Button Content="{Binding ButtonString}" />
在 ViewModel 中:
public String ButtonString
{
get
{
//There, define if there are any more things to display
}
}
4/ 你的Button 触发一个Command 启动一个方法,比如说GetMore():
<Button Content="{Binding ButtonString}" Command="{Binding GetMoreCommand} />
在 ViewModel 中:
private void GetMore()
{
//append to the _listElements new elements from the list
//Update the ButtonString if there are no more elements
}
你去吧!
(如果需要,您还可以定义一个按钮,例如从 ObservableCollection 中删除内容)