Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Save Button functionality
posted

Does someone have an example of placing a save button on a XamRibbon when using MVVM with PRISM.  I've placed my save button on its own tab and when I press the save button the method in the viewModel does not execute (only the method in the ViewModelBase).  I believe it's because the focus has changed, but I'm not sure.  Here's the signature of my ViewModelBase that all my view models inherit from:

public class ViewModelBase : BindableBase, INavigationAware, IActiveAware, IDockAware

{

       public DelegateCommand SaveCommand { get; set; }

       public ViewModelBase()

        {
            SaveCommand = new DelegateCommand(OnSave, CanSave);
        }

}

My ViewModel method:

protected override async void OnSave()
        {
            FooDTO dto = new FooDTO();
            await dto.Save(Foo);
        }

}

My XAML:

<IG1:RibbonTabItem Header="Home">
                    <IG1:RibbonGroup x:Name="HomeGroup"
                                     Caption="Home"
                                     Width="auto">                 
 
                        <IG1:ButtonTool x:Name="SaveBtn"
                                        Caption="Save"
                                        Content="Save"
                                    Command="{Binding SaveCommand}"
                                        IG1:RibbonGroup.MaximumSize="ImageAndTextLarge"
                                        LargeImage="/images/Save.png" />
 
                    </IG1:RibbonGroup>
                </IG1:RibbonTabItem>

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Kevin,

    I have built a simple sample project using the code that you have provided, and this seems to me that it is less of a Prism issue as it is more of a data-context assignation issue. This is to say that with this simple application and verifying that the "Save" button tool's data context is the ViewModel that is overriding the OnSave method, I cannot seem to reproduce this behavior that you are referring to, as the override is firing on my end.

    Out of curiosity, if you check the Output Window in Visual Studio, are you receiving a System.Windows.Data error anywhere in which the "SaveBtn" cannot find a member named "SaveCommand?" This will mean that the ButtonTool's data context cannot resolve the SaveCommand property, as it doesn't exist on its data context.

    I have attached the sample project I have used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.

    If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using.  My test was performed using version 16.2.20162.2109 of Infragistics for WPF 2016.2.

    If the project does show the product feature working correctly, this indicates a possible problem in the code of your application.  It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

    XamRibbonDelegateCommandTest.zip
Children
No Data