C# 子菜单项上的WPF上下文菜单绑定项源

C# 子菜单项上的WPF上下文菜单绑定项源,c#,wpf,xaml,C#,Wpf,Xaml,我的XAML <ContextMenu x:Key="ExportContext"> <MenuItem Header="Export Journey" Command="{Binding ExportJourney}"/> <MenuItem Header="Export..." ItemsSource="{Binding SelectedTrip.Cl

我的
XAML

    <ContextMenu x:Key="ExportContext">
        <MenuItem Header="Export Journey"
                  Command="{Binding ExportJourney}"/>
        <MenuItem Header="Export..."
                  ItemsSource="{Binding SelectedTrip.Clips}">
            <MenuItem.ItemTemplate>
                <DataTemplate>
                    <MenuItem Header="{Binding Name}"/>
                </DataTemplate>
            </MenuItem.ItemTemplate>
        </MenuItem>
    </ContextMenu>
旅程
类包含一个属性
剪辑
,它是一个
列表
。然后,
Clip
类包含要显示的
Name
的字符串属性

JourneyList
显示在
DataGrid
中,当选择一行时,
Journey
被设置为
SelectedTrip

我不明白为什么绑定到
ExportJourney
ICommand
可以完美地工作,但导出下没有显示任何内容。。。标题。 我唯一能想到的是,
SelectedJourney
在加载时为空

如果出于测试目的,我绑定到
JourneyList
而不是
SelectedTrip.Clips
绑定工作正常,我会得到一个子菜单(虽然没有名字,但位置在那里!)


不确定如何调试这个?非常感谢关于调试绑定的任何建议,或者关于我做错了什么的建议

在不到10分钟的时间里回答了我自己的问题,但我花了一周的时间在谷歌上把它发布到这里。我讨厌这个世界有时的运作方式

回答:
ContextMenu
上的
ItemsSource
不能是
列表
类型

我调整了我的
旅程
类,使public
Clip
属性成为
IEnumerable
(private
Clip
属性成为
可观察集合
),而不是
列表

namespace ViewModel
{
    class HomeViewModel: ObservableObject, IPageViewModel
    {
        private ICommand _exportJourney;
        private ObservableCollection<Journey> _journeyList = new ObservableCollection<Journey>();
        private Journey _selectedTrip;

        public IEnumerable<Journey> JourneyList
        {
           get { return _journeyList; }
        }

        public Journey SelectedTrip
        {
            get { return _selectedTrip; }
            set
            {
                if (_selectedTrip != value)
                {
                    _selectedTrip = value;
                    _journeyList.Where(c => c.Selected == true).ToList().ForEach(a => a.Selected = false);
                    _journeyList.Where(c => c.StartTime == value.StartTime).ToList().ForEach(a => a.Selected = true);
                    OnPropertyChanged("SelectedTrip");
                }
            }
        }

        public ICommand ExportJourney
        {
            get
            {
                if (_exportJourney == null)
                {
                    _exportJourney = new RelayCommand(
                        p => ExtractJourney(),
                        p => SelectedTrip != null);
                }

                return _exportJourney;
            }
        }
    }
}