1

Greatings,我正在创建一个 wpf 用户库控件,它有一个 windows 窗体控件。是否可以将值传递给属性类库控件(不是 Windows 窗体控件属性)?,我有这个:

WPF 用户控件库 (XAML):

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

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

</wfi:WindowsFormsHost>

……

WPF 用户控件库 (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();
     } 

在 WPF 应用程序中,MainPage (XAML) 与参考库:

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

WPF 应用程序,主页(C#):

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

            ViewModel viewModel = new ViewModel(); 
            DataContext = 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 
        }

但这不起作用。

4

3 回答 3

0

在互联网上搜索,我为您找到了许多解决方案。请查看以下页面:

演练:在 WPF 应用程序中使用 ReportViewer

在 WPF 中使用报表查看器控件

在 Windows Presentation Foundation (WPF) 中使用报表查看器控件

在 WPF 中使用 MS ReportViewer 包含一个很好的提示

MSDN 上的WindowsFormsHost.PropertyMap 属性页面显示了如何将 WPF 控件属性转换为 WinForms 属性,反之亦然。

通过 WindowsFormsHost 将参数从 WPF 用户控件传递到 Windows 窗体用户控件

在 WinForms 中集成 WPF 用户控件(反过来,但仍为您提供有效的方法)

更新>>>

我真的不明白你的问题。如果您真的不想遵循我给您的那些链接中的任何建议,只需创建一个在内部UserControl托管ReportViewer控件的 Windows 窗体并声明您需要的所有属性UserControl。然后像这样使用 XAML:

<wfi:WindowsFormsHost Height="300" Name="winFormsHost" VerticalAlignment="Top" >
    <YourWinFormsUserControlWithInternalReportViewer UrlServer="Something" 
        Path="Some/Path/Report.rdl" User="Geert" Password="password" />
</wfi:WindowsFormsHost>
于 2013-10-10T16:08:45.190 回答
0

您正在谈论嵌套用户控件问题。Catel 为您提供开箱即用的解决方案。看看它作为一个例子,或者只是将它用作你的应用程序的框架,这取决于你。

另一个很棒的功能是您可以通过简单的属性在视图和视图模型之间映射属性

于 2013-10-10T17:54:17.050 回答
0

使用EventHandler Delegate发布和订阅事件。当信息准备好时,提出事件并传递所需的信息EventArgs

于 2013-10-10T15:37:32.403 回答