I'm new to WPF and am trying to build an MRU (most recently used items) menu with the Fluent.Ribbon library.
Some digging in example code and the internet lead me to this point where I can generate the menuitems in splitbutton based on my list or recently used items. But I can't figure out how to wire these items up to by OpenCommand
class MainWindowVM : NotifyingObject
{
private ICommand openCommand;
private ObservableCollection<String> recentFileNames = new ObservableCollection<string>() { "Bellerophon", "Athena" };
public ICommand OpenCommand
{
get => openCommand;
}
public ObservableCollection<String> RecentFileNames
{
get => recentFileNames;
}
}
The Viewmodel is applied to the RibbonWindow
<Window.DataContext>
<vm:MainWindowVM />
</Window.DataContext>
And the current state of my Button is this:
<Fluent:SplitButton Header="Open..." Size="Middle"
Command="{Binding OpenCommand}"
ItemsSource="{Binding Path=RecentFileNames}">
<Fluent:SplitButton.Icon>
<Image Source="Icons/folder-open-document.png" />
</Fluent:SplitButton.Icon>
<Fluent:SplitButton.LargeIcon>
<Image Source="Icons/folder-open-document.png" />
</Fluent:SplitButton.LargeIcon>
<Fluent:SplitButton.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</Fluent:SplitButton.ItemTemplate>
<Fluent:SplitButton.ItemContainerStyle>
<Style TargetType="{x:Type Fluent:MenuItem}">
<Setter Property="Command"
Value="{Binding DataContext.OpenCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Fluent:MenuItem}, AncestorLevel=1}}" />
<!--Setter Property="CommandParameter" Value="{}" /-->
</Style>
</Fluent:SplitButton.ItemContainerStyle>
</Fluent:SplitButton>
I've adapted this code from another SO question running on normal menuitems. But my command isn't getting called. I know that I'll eventually have to pass a parameter to distinguish between the different items but I can't even get it to run the plain command.