2015-11-10 122 views
2

我目前正試圖通過將文件鏈接到wpf librarys來將我的silverlight項目更改爲wpf,以便以後我可以同時使用這兩個應用程序。我鏈接到我的WPF項目從我的Silverlight項目這個文件是給我這個錯誤:命名空間'System.Windows'中不存在類型或命名空間名稱'Deployment'

Error 27 The type or namespace name 'Deployment' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) C:\Users\sahluwai\Desktop\cusControls2\leitch\HarrisSilverlightToolkit\Toolkit\Source\Controls\Input\IpAddressControl\CcsIPAddressControl.cs 854 36 Input

我已經確定該文件已經「使用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; 
    } 

回答

2

不要System.Windows.Deployment使用調度程序 - 這是特定的Silverlight。如果您的意圖是調用屬於GUI的分派器上的某些內容,請改用System.Windows.Application.Current.Dispatcher

+0

然後爲委託裏面我開始得到這個錯誤:**不能轉換匿名方法鍵入'System.Delegate',因爲它不是一個委託類型**是否有一個簡單的解決方案呢? –

+0

@SumitSingh你需要將匿名方法轉換爲委託,可能是'Action'。例如,''System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)delegate(){MessageBox.Show(「Hi」,「Error」,MessageBoxButton.OK);});' – vcsjones

+0

是的。 –

相關問題