【问题标题】:The type or namespace name 'Deployment' does not exist in the namespace 'System.Windows'命名空间“System.Windows”中不存在类型或命名空间名称“部署”
【发布时间】:2016-02-11 17:43:13
【问题描述】:

我目前正在尝试通过将文件链接到 wpf 库来将我的 silverlight 项目更改为 wpf,以便以后我可以同时使用这两个应用程序。我从我的 silverlight 项目链接到我的 wpf 项目的这个文件给了我这个错误:

错误 27 命名空间“System.Windows”中不存在类型或命名空间名称“Deployment”(您是否缺少程序集引用?) C:\Users\sahluwai\Desktop\cusControls2\leitch\HarrisSilverlightToolkit\Toolkit\ Source\Controls\Input\IpAddressControl\CcsIPAddressControl.cs 854 36 输入

我已确保文件顶部有“使用 System.Windows”。

这是函数的样子,有错误(请查看注释以查看示例错误位置):

private bool ValidateIpOctet(TextBox IpOctet, int OctetIndex)
    {
        bool redraw = false;

        if (OctetIndex < 0 || OctetIndex >= this.m_IpAddress.IpOctets.Length)
            return redraw;

        int i = OctetIndex;

        this.m_IpAddress.IpOctets[i] = String.IsNullOrEmpty(IpOctet.Text) ? "0" : IpOctet.Text;

        uint iOctet = uint.Parse(this.m_IpAddress.IpOctets[i]);
        if (i == 0)
        {
            if (Rule == NetworkInterfaceRule.IP || Rule == NetworkInterfaceRule.GATEWAY)
            {
                if (iOctet > 223)
                {
                    redraw = true;
                    this.m_IpAddress.IpOctets[i] = "223";
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
                        delegate()
                        {
                            MessageBox.Show(String.Format("{0} is not a valid entry. Please specify a value between 1 and 223.", this.IpAddress), "Error", MessageBoxButton.OK);
                        });
                }
                else if (iOctet < 1)
                {
                    redraw = true;
                    this.m_IpAddress.IpOctets[i] = "1";
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
                        delegate()
                        {
                            MessageBox.Show(String.Format("{0} is not a valid entry. Please specify a value between 1 and 223.", this.IpAddress), "Error", MessageBoxButton.OK);
                        });
                }
            }
            else
            {
                if (iOctet > 255)
                {
                    redraw = true;
                    this.m_IpAddress.IpOctets[i] = "255";


 /////////////////////////////////////////////////////////////////////////
 //////////////////////this is one place where i am facing this error:

                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
                        delegate()
                        {
                            MessageBox.Show(String.Format("{0} is not a valid entry. Please specify a value between 0 and 255.", this.IpAddress), "Error", MessageBoxButton.OK);
                        });
                }
                else if (iOctet < 0)
                {
                    redraw = true;
                    this.m_IpAddress.IpOctets[i] = "0";
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
                        delegate()
                        {
                            MessageBox.Show(String.Format("{0} is not a valid entry. Please specify a value between 0 and 255.", this.IpAddress), "Error", MessageBoxButton.OK);
                        });
                }
            }
        }
        else
        {
            if (iOctet > 255)
            {
                redraw = true;
                this.m_IpAddress.IpOctets[i] = "255";
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
                    delegate()
                    {

                        MessageBox.Show(String.Format("{0} is not a valid entry. Please specify a value between 0 and 255.", this.IpAddress), "Error", MessageBoxButton.OK);
                    });
            }
            else if (iOctet < 0)
            {
                redraw = true;
                this.m_IpAddress.IpOctets[i] = "0";
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
                    delegate()
                    {
                        MessageBox.Show(String.Format("{0} is not a valid entry. Please specify a value between 0 and 255.", this.IpAddress), "Error", MessageBoxButton.OK);
                    });
            }
        }

        this.IpAddress = this.m_IpAddress.ToString();
        return redraw;
    }

【问题讨论】:

    标签: c# .net wpf silverlight namespaces


    【解决方案1】:

    不要使用来自 System.Windows.Deployment 的调度程序 - 这是 Silverlight 特有的。如果您的意图是调用属于 GUI 的 Dispatcher 上的某些内容,请改用 System.Windows.Application.Current.Dispatcher

    【讨论】:

    • 然后对于内部的委托,我开始收到此错误:无法将匿名方法转换为类型“System.Delegate”,因为它不是委托类型这也是?
    • @SumitSingh 您需要将匿名方法强制转换为委托,可能是Action。例如,System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)delegate () { MessageBox.Show("Hi", "Error", MessageBoxButton.OK); });
    猜你喜欢
    • 2022-01-11
    • 2014-03-04
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    相关资源
    最近更新 更多