1

Greatings, I'm creating a wpf user library control, which has a windows form control. Is possible pass values to properties class library control (not windows forms control properties)?, I have this:

WPF User Control Library (XAML):

<wfi:WindowsFormsHost Height="300" Name="winFormsHost" VerticalAlignment="Top" >

   <wfr:ReportViewer x:Name="rptViewer" ProcessingMode="Remote"/>

</wfi:WindowsFormsHost>

....

WPF User Control Library (C#):

public partial class ReportViewer : UserControl
{

        public static readonly DependencyProperty UrlReportServerProperty =
            DependencyProperty.Register("UrlReportServer", typeof(string),    typeof(ReportViewer),
                                        new PropertyMetadata((string)""));
.... // Other Dependecies properties

     public string UrlReportServer
     {
        get { return (string)GetValue(UrlReportServerProperty);}
        set { SetValue(UrlReportServerProperty, value); }
     }
............ // Other properties

     public ReportViewer()
     {
            InitializeComponent();
            this.DataContext = this;

            ReportViewerLoad();
     }
     public void ReportViewerLoad()
     {
             rptViewer.ProcessingMode = ProcessingMode.Remote;

             rptViewer.ServerReport.ReportServerUrl =
                        new Uri(UrlReportServer);
...... //Pass credentials to server reports and parameters to Report with Properties.

             rptViewer.ServerReport.Refresh();
                this.rptViewer.RefreshReport();
     } 

In WPF App, MainPage (XAML) with the reference library:

<WPFControlsSol:ReportViewer HorizontalAlignment="Left" Margin="0,0,0,0" 
                             VerticalAlignment="Top" Width="644"
                             UrlReportServer="{Binding Url}"
</WPFControlsSol:ReportViewer>

WPF App, MainPage (C#):

public partial class MainPageView : Window
{
        public MainPageView()
        {
            InitializeComponent();

            ViewModel viewModel = new ViewModel(); 
            DataContext = viewModel;

        }
}

In ViewModel:

public class ViewModel : ViewModelBase
{

        private string _url;  .... // Other attributes

        public string Url
        {
            get { return _url; }
            set 
            {
                if (_url != value)
                {
                    _url = value;
                    RaisePropertyChanged("Url"); //Notification Method own MVVM  Template I use.
                }
            }
        } .... // Other properties 



        public ViewModel()
        {

           LoadReport();
        }  



        public void LoadReport()
        {
            Url = "http://IPSERVER"; .... // Other properties 
        }

But This not works.

chriga
  • 798
  • 2
  • 12
  • 29
Ejrr1085
  • 975
  • 2
  • 16
  • 29
  • Please tell us exactly what you are trying to achieve by passing these parameters and which parameters you are talking about. – Sheridan Oct 10 '13 at 14:40
  • I have a WPF MVVM Application that need load a Report (.rdl), the report is hosted in Server Report, I need access to report with credentials (urlserver, report path, user, password) and pass parameters for show in report. The only control can do this is ReportViewer from Windows Forms, I want do a WPF Control User Library that has the ReportViewer control. My idea is used this WPF Control in others WPF App with others Reports only load the control and pass the credential and parameters. – Ejrr1085 Oct 10 '13 at 15:06
  • Why are you using WindowsFormsHost control for hosting your WPF User Control, in your WPF Control Library? May be WindowsFormsHost should be created and loaded from inside your WPF User Control's C# code...!! – S2S2 Oct 10 '13 at 15:46
  • Yes, I'm using WindowsFormsHost... I go to test the ReportViewer control created and loaded inside WPF User Control's C#. – Ejrr1085 Oct 10 '13 at 15:54
  • How add the ReportViewer Control to WindowsFormsHost in C#? – Ejrr1085 Oct 10 '13 at 16:14

3 Answers3

0

Use the EventHandler Delegate to publish and subscribe an event. WHen information is ready, raise the event and pass along the information required in the EventArgs

0

Searching the internet, I found a number of solutions for you. Please take a look at the following pages:

Walkthrough: Using ReportViewer in a WPF Application

Using Report Viewer Control in WPF

Using a Report Viewer Control in Windows Presentation Foundation (WPF)

Using MS ReportViewer in WPF contains a good tip

WindowsFormsHost.PropertyMap Property page on MSDN shows how to translate WPF control properties to WinForms properties and vice versa.

Pass parameters from WPF user control to Windows Form User Control via WindowsFormsHost

Integrate WPF UserControls in WinForms (The other way around, but still provides a valid method for you)

UPDATE >>>

I don't really understand your problem. If you really don't want to follow any advice from those links I gave you, just create a Windows Forms UserControl that hosts the ReportViewer control internally and declare all the properties that you need on that UserControl. Then use XAML like this:

<wfi:WindowsFormsHost Height="300" Name="winFormsHost" VerticalAlignment="Top" >
    <YourWinFormsUserControlWithInternalReportViewer UrlServer="Something" 
        Path="Some/Path/Report.rdl" User="Geert" Password="password" />
</wfi:WindowsFormsHost>
Community
  • 1
  • 1
Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • My case is the parameters are not reportviewer's properties, the parameters are variables to access to report, and I don't know how to pass this type of parameters to WPF User Control Library. – Ejrr1085 Oct 10 '13 at 20:06
  • I tried add properties to Control, like you suggest but not works. I have a WPF MVVM Application that need load a Report (.rdl), the report is hosted in Server Report, I need access to report with credentials (urlserver, report path, user, password) and pass parameters for show in report. The only control can do this is ReportViewer from Windows Forms, I want do a WPF Control User Library that has the ReportViewer control. My idea is used this WPF Control in others WPF App with others Reports only load the control and pass the credential and parameters. – Ejrr1085 Oct 10 '13 at 23:52
  • Dude, repeating yourself doesn't help. Either way, I'm now done with this, so good luck to you. – Sheridan Oct 11 '13 at 08:04
0

You are talking about the nested user controls problem. Catel provides and out of the box solution for you. Take a look at it as an example or just use it as the framework for your app, that is up to you.

Another great feature is that you can map properties between views and view models via easy attributes.

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32