部署代码中的WPF绑定错误 [英] WPF Binding Error in Deployment Code

查看:72
本文介绍了部署代码中的WPF绑定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在部署代码中获取错误,因为对ReportTemplateVM类型的构造函数的调用与指定的绑定约束相匹配引发了异常"
我已经实现了MVVM模式.
DXGrid正在显示记录&其项目源属性绑定在各自的视图模型构造函数中

模型文件

Getting Error in deployment code as "The invocation of the constructor on type ReportTemplateVM matches specified binding constraints threw an exception"
I have implemented MVVM pattern.
DXGrid is showing records & its item source property in binded in respective view models constructor

Model file

namespace ReportGenerator.Models
{
    internal class ReportTemplateModel:INotifyPropertyChanged
    {

        #region Public Porperties
        private DataTable gridData;
        public DataTable GridData
        {
            get { return gridData; }
            set
            { 
                gridData = value;
                OnPropertyChanged("GridData");
            }
        }

}

查看模型文件

View Model file

namespace ReportGenerator.ViewModels
{
    internal class ReportTemplateVM
    {
        ReportDocument O_Report = new ReportDocument();
        CrystalReportViewer rptViewer = new CrystalReportViewer();
        WindowsFormsHost host = new WindowsFormsHost();
        ReportData rptData = new ReportData();
        public static int selectedID;
        IDBManager objDbManager = new DBManager(DataProvider.SqlServer);
        public ReportTemplateModel rptTempModel { get; set; }

        public ReportTemplateVM()
        {
            //This data will load as the default Data from the ReportTemplateModel attached to the view
           // LoadGrid();
        }

        #region Methods
        /// <summary>
        /// Methods for set data to grid on load as well as when Refresh
        /// </summary>
        public void LoadGrid()
        {
            try
            {
                rptTempModel = new ReportTemplateModel { GridData = rptData.GetData() };
            }
            catch (Exception ex)
            {
                DXMessageBox.Show(ex.Message);
            }
        }

查看文件

<usercontrol x:class="ReportGenerator.Views.ucReports" xmlns:x="#unknown"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"

             mc:Ignorable="d"

             xmlns:cn="clr-namespace:ReportGenerator.Commands"

             xmlns:ws="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"

             xmlns:crystal="clr-namespace:CrystalDecisions.Windows.Forms;assembly=CrystalDecisions.Windows.Forms"

             xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"

             d:DesignHeight="778" d:DesignWidth="1100" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"

             xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"

             xmlns:local="clr-namespace:ReportGenerator.Views"

             xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"



             xmlns:vm="clr-namespace:ReportGenerator.ViewModels"&gt;

  <stackpanel height="700">
        <stackpanel.datacontext>
            <vm:reporttemplatevm xmlns:vm="#unknown" />
        </stackpanel.datacontext>
        <textblock>Hi</textblock>
                <dxdo:docklayoutmanager name="dockLayoutManager1" height="700" width="1100" maxwidth="1050" maxheight="700" minheight="50" minwidth="50" horizontalcontentalignment="Stretch" xmlns:dxdo="#unknown">
          <dxdo:docklayoutmanager.floatgroups>
              <dxdo:floatgroup floatlocation="1.77874186550974,1" floatsize="995,282" height="290" orientation="Vertical">
               <dxdo:layoutpanel height="290" margin="0" maxsize="1100,290" padding="0" width="1100">
                 <stackpanel width="995" margin="0" height="250" orientation="Vertical">
                            <stackpanel margin="1,1,1,1">
                                <dxg:gridcontrol x:name="Grid1" dockpanel.dock="Top" width="985" height="195" verticalalignment="Stretch" horizontalalignment="Stretch" autopopulatecolumns="True" allowdrop="True" margin="5" isrecursiveexpand="True" autoexpandallgroups="True" maxwidth="995" maxheight="500" minwidth="50" minheight="50" uselayoutrounding="True" panel.zindex="1" xmlns:dxg="#unknown">
                            <dxg:gridcontrol.view>
                                <dxg:tableview name="view" autowidth="True" visibility="Visible" navigationstyle="Row" allowmoving="True" showgrouppanel="False" />
                            </dxg:gridcontrol.view>
                        </dxg:gridcontrol>
                   </stackpanel>
                   <stackpanel height="35" orientation="Horizontal" width="995"

                                &lt;Button Background="LightBlue" Content="_Refresh" Height="23" IsHitTestVisible="True" Margin="5" Name="Refresh" Opacity="1" Visibility="Visible" Width="90"/&gt;

                                &lt;Button Background="LightBlue" Content="_Add New Report" Height="23" IsHitTestVisible="True" Margin="5" Name="btnAddRow" Opacity="1" Visibility="Visible" Width="90" /&gt;

                                &lt;Button Background="LightBlue" Content="_Update" Height="23" IsHitTestVisible="True" Margin="5" x:Name="Update" Opacity="1" Visibility="Visible" Width="90"/&gt;

                                &lt;Button Background="LightBlue" Content="_Delete" Height="23" IsHitTestVisible="True" Margin="5" Name="Delete" Opacity="1" Visibility="Visible" Width="90"/&gt;

                                &lt;Button Background="LightBlue" Content="_Generate Report" Height="23" IsHitTestVisible="True" Margin="5" Name="btnRptGenerate" Opacity="1" Visibility="Visible" Width="90"/&gt;

                                &lt;Button Background="LightBlue" Content="Preview" Height="23" IsHitTestVisible="True" Margin="5" Name="btnPreview" Opacity="1" Visibility="Visible" Width="90"/&gt;

                  </stackpanel>
                 </stackpanel>
               </dxdo:layoutpanel>
              </dxdo:floatgroup>
              <dxdo:floatgroup floatlocation="179.522388059701,382" floatsize="995,250" margin="0">
                    <dxdo:layoutpanel caption="Report Preview" height="460" padding="0" width="1000" margin="0" maxsize="1100,460">
                        <stackpanel x:name="ParentStack" margin="0">
                            <contentcontrol height="460" width="985" margin="0" padding="0" name="Report" />
                        </stackpanel>
                    </dxdo:layoutpanel>
               </dxdo:floatgroup>
          </dxdo:docklayoutmanager.floatgroups>
       </dxdo:docklayoutmanager>
  </stackpanel>
</usercontrol>

推荐答案

It looks like you are using xpo[^] - why don''t you bind directly to an XPCollection or XPQuery?


最好的问候
Espen Harlinn
It looks like you are using xpo[^] - why don''t you bind directly to an XPCollection or XPQuery?


Best regards
Espen Harlinn


这篇关于部署代码中的WPF绑定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆