0
Menu.Pages绑定的ListBox对象充满了这一点:RelayCommand在视图模型不包含在XAML命令
this.Menu = new Menu()
{
Pages = new List<Page>()
{
new Page() {
Title = "ergre",
URI = "rgerg"
},
new Page() {
Title = "herth",
URI = "wefwe"
}
}
};
我有以下XAML:
<ListBox Grid.Column="0"
Grid.Row="1"
x:Name="Pages"
ItemsSource="{Binding Menu.Pages}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Button Command="{Binding ElementName=Pages, Path=DataContext.ButtonCommand_LoadGagPage}">
<TextBlock Text="{Binding Title}"></TextBlock>
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
命令绑定按钮正确触发以下方法:
...
ButtonCommand_LoadGagPage = new RelayCommand<Page>((param) => ButtonCommand_ExecuteLoadGagPage(param));
...
public RelayCommand<Page> ButtonCommand_LoadGagPage
{
get;
private set;
}
public void ButtonCommand_ExecuteLoadGagPage(Page page)
{
// page is null :(?
}
但是,页面变量e不包含该页面。我如何正确连接对象...