Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm using C# WPF application to display crystal reports and i want to call a function when crystal report viewer refresh button is clicked.

so in viewer properties i set command binding to refresh and application XAML looks like below

C++
<Grid>
    <cr:CrystalReportsViewer Name="reportViewer">
        <cr:CrystalReportsViewer.CommandBindings>
            <CommandBinding Command="NavigationCommands.Refresh"/>
        </cr:CrystalReportsViewer.CommandBindings>
    </cr:CrystalReportsViewer>
</Grid>


any idea how to capture this refresh event and call the command handler?

Regards
Posted

1 solution

Basically it's not only you need to bind the command but you need to associate events as well. For example
HTML
  <commandbinding command="ApplicationCommands.Close">
                  Executed="CloseCommandHandler"
                  CanExecute="CanExecuteHandler"/>
</commandbinding>

C#
// Create the CommandBinding.
CommandBinding CloseCommandBinding = new CommandBinding(
    ApplicationCommands.Close, CloseCommandHandler, CanExecuteHandler);

// Add the CommandBinding to the root Window.
RootWindow.CommandBindings.Add(CloseCommandBinding);

// Executed event handler.
private void CloseCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
    // Calls a method to close the file and release resources.
    // Do something
}
// CanExecute event handler.
private void CanExecuteHandler(object sender, CanExecuteRoutedEventArgs e)
{   // If something is true then
    if (true)
        e.CanExecute = true;
    // If not, avoid execute
    else
        e.CanExecute = false;
}


For more how about reading the examples listed in the following MSDN article. Commanding Overview[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jan-12 14:50pm    
Good answer, my 5.
--SA
Wonde Tadesse 29-Jan-12 15:32pm    
Thanks
Espen Harlinn 29-Jan-12 16:12pm    
I agree, my 5 too :)
Wonde Tadesse 29-Jan-12 16:19pm    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900