2012-11-09 26 views
0

我正在執行教程我在Expression Blend 4中發現了使用WPF連接到SQL Server。在完成VS12的最後一步之後,我得到以下錯誤。我可以使用Visual Studio 12中的Clean <項目名稱>嗎?

Error 1 The type or namespace name 'DelegateCommand' could not be found (are you missing a using directive or an assembly reference?) 
Error 2 The type or namespace name 'DelegateCommand' could not be found (are you missing a using directive or an assembly reference?) 

當我做乾淨我不明白這些錯誤。 我的目標是.net 4.5我也試過4.0

我的代碼這是錯誤的看起來像這樣。我粗體顯示了兩條錯誤行。這是一個文件叫Class1.cs

using System; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 


namespace AWADataSource 
{ 
public class ProductPhotosCollection 
{ 
    **private DelegateCommand getDataCommand; 
    public DelegateCommand GetDataCommand { get { return getDataCommand; } }** 
    public ProductPhotosCollection() 
    { 
     getDataCommand = new DelegateCommand(delegate() { GetData(); }); 
    } 


    public ObservableCollection<ProductPhoto> ProductPhotos 
    { get { return this.productPhotos; } } 
    private ObservableCollection<ProductPhoto> productPhotos = 
     new ObservableCollection<ProductPhoto>(); 
    private void GetData() 
    { 
     ProductPhotosTableAdapters.ProductPhotoTableAdapter da = 
      new ProductPhotosTableAdapters.ProductPhotoTableAdapter(); 
     ProductPhotos.ProductPhotoDataTable dt = da.GetData(); 
     productPhotos.Clear(); 
     foreach (ProductPhotos.ProductPhotoRow row in dt) 
     { 
      productPhotos.Add(new ProductPhoto(
       row.ProductPhotoID, 
       row.ThumbNailPhoto, 
       row.LargePhoto, 
       row.ModifiedDate)); 
     } 
    } 
} 
public class ProductPhoto 
{ 

    // Public Accessors to the private properties. 
    public int ID { get { return id; } } 
    public ImageSource ThumbNailPhoto { get { return thumbNailPhoto; } } 
    public ImageSource LargePhoto { get { return largePhoto; } } 
    public DateTime ModifiedDate { get { return modifiedDate; } } 

    // Constructor. 
    public ProductPhoto(int id, byte[] thumbNailPhoto, byte[] largePhoto, 
     DateTime modifiedDate) 
    { 
     this.id = id; 
     this.thumbNailPhoto = ByteArrayToImageSource(thumbNailPhoto); 
     this.largePhoto = ByteArrayToImageSource(largePhoto); 
     this.modifiedDate = modifiedDate; 
    } 

    // Private properties. 
    private int id; 
    private ImageSource thumbNailPhoto; 
    private ImageSource largePhoto; 
    private DateTime modifiedDate; 

    // Supporting method. 
    private ImageSource ByteArrayToImageSource(byte[] data) 
    { 
     BitmapImage image = null; 
     if (null != data) 
     { 
      image = new BitmapImage(); 
      image.BeginInit(); 
      image.StreamSource = new System.IO.MemoryStream(data); 
      image.EndInit(); 
     } 
     return image; 
     } 
    } 
} 

和我的其他文件被稱爲DelegateCommand.cs這幾乎是一個副本和paist。

namespace AWDataSource 
{ 
using System; 
using System.Windows.Input; 

/// 
/// DelegateCommand is a simplified version of ICommand in WPF. You can wrap one of these around any method, 
/// and thus bind any command on any WPF object to your method. 
/// 
/// DelegateCommand also supports an IsEnabled property that you can use to turn the command on and off. 
/// 
public sealed class DelegateCommand : ICommand 
{ 
    // Remember the method so that it can be called at the right time. 
    private SimpleEventHandler handler; 

    // Maintain the enabled state. 
    private bool isEnabled = true; 

    // Type signature of the method that DelegateCommand works with - returns void, no arguments. 
    public delegate void SimpleEventHandler(); 

    // Simple constructor: Pass in the method that needs to be called when the command executes. 
    public DelegateCommand(SimpleEventHandler handler) 
    { 
     this.handler = handler; 
    } 

    #region ICommand implementation 

    // Executing the command is as simple as calling the method. 
    void ICommand.Execute(object arg) 
    { 
     this.handler(); 
    } 

    // Saying whether the command can be executed. 
    bool ICommand.CanExecute(object arg) 
    { 
     return this.IsEnabled; 
    } 

    // This is the event that the command architecture of WPF listens to so it knows when to update 
    // the UI on command enable/disable. 
    public event EventHandler CanExecuteChanged; 
    #endregion 

    // Public visibility of the isEnabled flag - note that when it is set, the event must be raised 
    // so that WPF knows to update any UI that uses this command. 
    public bool IsEnabled 
    { 
     get { return this.isEnabled; } 
     set 
     { 
      this.isEnabled = value; 
      this.OnCanExecuteChanged(); 
     } 
    } 

    // Simple event propagation that makes sure that someone is listening to the event before raising it. 
    private void OnCanExecuteChanged() 
    { 
     if (this.CanExecuteChanged != null) 
     { 
      this.CanExecuteChanged(this, EventArgs.Empty); 
     } 
     } 
    } 
} 

回答

2

ProductPhotosCollection是在命名空間AWADataSourceDelegateCommandAWDataSource

可能是一個錯字,但您可能需要將它們放在同一個命名空間,或使用using導入AWDataSource命名空間到ProductPhotosCollection(或你的情況「將Class1.cs」)

+0

謝謝,我已經chaseing那個早晨,我一直在重新修復,並得到同樣的錯誤。 – StephanM

相關問題