Hi All!
I've created an application ribbon which is working very nicely using the MVVM pattern (C# / WPF). I therefore have a RibbonButtonViewmodel, for example, which inherits RibbonItemViewmodel. This provides Headertext, Icons and so on for the actual RibbonButton which is created using a TemplateSelector. All good so far.
My issue now is that when I display a document in my application (document editing is just a small part of the application), I display a "Documents" tab in the ribbon bar and would like, e.g., Cut, Copy, Paste, Bold... commands.
I completely understand how to do this using pure MVVM:
Content="Bold" Command="RichTextBoxAdv:SfRichTextBoxAdv.BoldCommand" CommandTarget="{Binding ElementName=richTextBoxAdv}"/>
However - as my buttons are so generic, I want command binding ie:
Add(new RibbonButtonViewmodel()
{
HeaderText= "Paste",
SizeForm = RibbonSizeForm.Large,
ClickCommand = SfRichTextBoxAdv.BoldCommand,
CommandTarget = RichTextBoxObject
});
Content="Bold" Command="{Binding ClickCommand}" CommandTarget="{Binding CommandTarget}"/>
This would allow me to keep my views / VM's much more generic. I even tried setting "ClickCommand" to a lambda but don't then really know how to call the command on the associated RichTextbox. Debugging shows that my "CommandTarget" in my view model does point to the correct SfRichTextBoxAdv control.
Any ideas how to achieve this?
EDIT: By "not working" I mean that the buttons are greyed out, so presumably "CanExecute" and "Execute" are not binding to the rich text box. The command buttons I create with the first code snippet above (using the more explicit code) are enabling and disabling as you would expect.