SL ReportView - Add Buttons & Commands

8 posts, 0 answers
  1. Manuel
    Manuel avatar
    36 posts
    Member since:
    Jul 2010

    Posted 30 Jan 2012 Link to this post

    Hello,

    I added two Buttons to the default Silverlight ReportViewer Style.

    Now I like to bind these two Buttons to a command.
    For this I made a class which inherited from ReportViewerModel.
    Unfortunatly this will not work. The ReportViewerModel as no contstructor.
    Error Message: Telerik.ReportViewer.Silverlight.ReportViewerModel Type has no constructors defined'

    My question:
    How can I bind Commands to the two new Buttons in the Style?

    Thank you,
    Manuel

  2. Steve
    Admin
    Steve avatar
    10942 posts
    Member since:
    May 2014

    Posted 01 Feb 2012 Link to this post

    Hi Manuel,

    The ReportViewerModel constructor is internal and cannot be inherited. Please elaborate what is your goal, what action do you want to perform on these new buttons you've added?

    Regards,
    Steve
    the Telerik team

    Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

  3. Manuel
    Manuel avatar
    36 posts
    Member since:
    Jul 2010

    Posted 01 Feb 2012 Link to this post

    Hello Steve,

    in passed Version of the Reporting (I guess < Q2 2011) it was working without any problems.
    I do not understand why the constructor is now internal / hidden for me.

    Anyway, I am using prism.
    The ReportViewer is in one of the regions. On the left, right and top of the reportviewer I have three other regions.
    On of the Buttons will hide the other regions (make the ReportViewer fullscreen), the other button will close the ReportViewer and show the "orginal" center region.

    It would be great to bind the Commands of the TelerikViewStyle to the ViewModel.

    Thank you,
    Manuel

  4. IvanY
    Admin
    IvanY avatar
    413 posts
    Member since:
    Sep 2012

    Posted 06 Feb 2012 Link to this post

    Hi Manuel,

    In order to bind the commands you have first to extract the ReportViewerModel from the DataContext of the ReportViewer. Once you extract it you will be able to recover the functionality from the previous version. This is a sample how to extract the ReportViewerModel:

    var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
    var reportViewerModel = (ReportViewerModel)(layoutRoot.DataContext);

    However ReportViewerModel in both Silverlight and WPF report viewers is intended for internal use by the controls and a better approach would be to add some external buttons that control the hiding/maximizing of the Report Viewer.

    Greetings,
    IvanY
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

  5. Manuel
    Manuel avatar
    36 posts
    Member since:
    Jul 2010

    Posted 14 Feb 2012 Link to this post

    Hi IvanY,

    this is a complete different approch than I used before.
    Can you create a small Demo Project please?

    Thank you,
    Manuel

  6. IvanY
    Admin
    IvanY avatar
    413 posts
    Member since:
    Sep 2012

    Posted 17 Feb 2012 Link to this post

    Hi Manuel,

    Here is a sample on how you can use the MoveToFirstPageCommand from the ReportViewerModel:

    public partial class MainPage : UserControl
    {
        MyViewModel myViewModel;
        public MainPage()
        {
            InitializeComponent();
            this.LayoutUpdated += new EventHandler(MainPage_LayoutUpdated);
        }
     
        void MainPage_LayoutUpdated(object sender, EventArgs e)
        {
            var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
            var reportViewerModel = (ReportViewerModel)(layoutRoot.DataContext);
            this.Initialize();
            myViewModel.MyCommand = reportViewerModel.MoveToFirstPageCommand;
        }
     
        void Initialize()
        {
            myViewModel = new MyViewModel();
        }
    }


    Regards,
    IvanY
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

  7. Manuel
    Manuel avatar
    36 posts
    Member since:
    Jul 2010

    Posted 23 Feb 2012 Link to this post

    Ivany,

    in your example you are using an existing command in the ReportViewModel.

    myViewModel.MyCommand = reportViewerModel.MoveToFirstPageCommand

    I don't like to override this command (MoveToFirstPageCommand), I like to add a new Command.
    How can I a new Command to the ReportViwerModel??

    Thank you,
    Manuel

  8. IvanY
    Admin
    IvanY avatar
    413 posts
    Member since:
    Sep 2012

    Posted 27 Feb 2012 Link to this post

    Hi Manuel,

    As the constructor of the ReportViewerModel is internal it is not possible to add new commands to the view model, you can only extract it and use the existing ones. However in your case a better approach (mentioned in one of my previous posts) would be to add some external buttons that control the hiding/maximizing of the Report Viewer, as it is just a control which can be manipulated easily in your case.

    Regards,
    IvanY
    the Telerik team

    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.

Back to Top