KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a main menu mnuMainMenu consisting of several sub-menus. One of the sub-menus mnuMostRecentDirs is itself another menu that has it's items generated at run time, using the ItemSource property bound to an ObservableCollection. Basically it's displaying a list of the most recently used folders. The issue is that the MenuItems added dynamically generate the following data binding error: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') The XAML declaration of the main menu goes something like this: <!-- Main Menu --> <Menu x:Name="mnuMainMenu" Height="Auto" IsMainMenu="True"> <!--- ... more menu declarations before ... --> <MenuItem x:Name="mnuitemWorkDirs" Header="Directories"> <MenuItem x:Name="mnuNewDir" Header="New" Style="{StaticResource MenuItem}" Command="{x:Static cmds:Commands.NewDirectory}" /> <MenuItem x:Name="mnuCurrentDir" Header="Current" Style="{StaticResource MenuItem}" Command="{x:Static cmds:Commands.CurrentDirectory}" /> <MenuItem x:Name="mnuMostRecentDirs" Header="Recent Directories.." Style="{StaticResource MenuItem}" ItemsSource="{Binding ElementName=theMain, Path=MostRecentFoldersList}" /> </MenuItem> <!--- ... more menu declarations after ... --> </Menu> And the foll
Tags (comma-separated)
Save Edits
Cancel