【发布时间】:2013-10-18 08:45:47
【问题描述】:
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;
}
}
在 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
}
但这不起作用。
【问题讨论】:
-
请准确告诉我们您通过传递这些参数想要实现的目标以及您所谈论的参数。
-
我有一个 WPF MVVM 应用程序需要加载报告 (.rdl),报告托管在服务器报告中,我需要使用凭据(urlserver、报告路径、用户、密码)访问报告和传递参数以在报告中显示。唯一可以做到这一点的控件是 Windows 窗体中的 ReportViewer,我想做一个具有 ReportViewer 控件的 WPF 控件用户库。我的想法是在其他 WPF App 中使用这个 WPF 控件和其他报表只加载控件并传递凭据和参数。
-
为什么在 WPF 控件库中使用 WindowsFormsHost 控件来托管 WPF 用户控件?可能应该从您的 WPF 用户控件的 C# 代码中创建和加载 WindowsFormsHost...!!
-
是的,我正在使用 WindowsFormsHost... 我去测试在 WPF 用户控件的 C# 中创建和加载的 ReportViewer 控件。
-
C#中如何将ReportViewer控件添加到WindowsFormsHost?