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不包含該頁面。我如何正確連接對象...