我创建了一个由这三个类组成的 WP 类库BusinessLogic项目
1)瓶类
namespace BusinessLogic
{
    public class Bottle : INotifyPropertyChanged
    {
        // Due to INotifyPropertyChanged interface
        public event PropertyChangedEventHandler PropertyChanged;
        // Proprietà Title
        private string title;
        public string Title
        {
            set
            {
                if (title != value)
                {
                    title = value;
                    OnPropertyChanged("Title");
                }
            }
            get
            {
                return title;
            }
        }
        // Proprietà PhotoFileName
        private string photoFileName;
        public string PhotoFileName
        {
           set
            {
                if (photoFileName != value)
                {
                    photoFileName = value;
                    OnPropertyChanged("PhotoFileName");
                }
            }
            get
            {
                return photoFileName;
            }
        } 
    protected virtual void OnPropertyChanged(string propChanged)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propChanged));
    }
  }
}
2)瓶子类
namespace BusinessLogic
{
    public class Bottles : INotifyPropertyChanged
    {
        // Due to INotifyPropertyChanged interface
        public event PropertyChangedEventHandler PropertyChanged;
        // Proprietà MainTitle
        private string mainTitle;
    public string MainTitle
    {
        set
        {
            if (mainTitle != value)
            {
                mainTitle = value;
                OnPropertyChanged("MainTitle");
            }
        }
        get
        {
            return mainTitle;
        }
    }
    // Proprietà bottles
    private ObservableCollection<Bottle> bottleSet = new ObservableCollection<Bottle>();
    public ObservableCollection<Bottle> BottleSet
    {
        set
        {
            if (bottleSet != value)
            {
                bottleSet = value;
                OnPropertyChanged("BottleSet");
            }
        }
        get { return bottleSet; }
    }
    protected virtual void OnPropertyChanged(string propChanged)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propChanged));
    }
}
}
3) BottlesPresenter类
namespace BusinessLogic
{
    public class BottlesPresenter : INotifyPropertyChanged
    {
    // Due to INotifyPropertyChanged interface
    public event PropertyChangedEventHandler PropertyChanged;
    // Proprietà BottleMatrix
    private Bottles bottlesMatrix;
    public Bottles BottlesMatrix
    {
        protected set
        {
            if (bottlesMatrix != value)
            {
                bottlesMatrix = value;
                OnPropertyChanged("BottlesMatrix");
            }
        }
        get { return bottlesMatrix; }
    }
    public BottlesPresenter()
    {
        XmlSerializer xml = new XmlSerializer(typeof(Bottles));
        using (StreamReader fileReader = new         StreamReader(@"C:\Stuff\WindowsPhone\AppLearningHowTo2\AppLearningHowTo2\DAL\DB.xml"))
        {
            BottlesMatrix = (Bottles)xml.Deserialize(fileReader);
        }
    }
        protected virtual void OnPropertyChanged(string propChanged)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propChanged));
        }
    }
}
BottlePresenter 构造函数应该从位于文件系统中的 xml 文件反序列化。它包含以下标签
<?xml version="1.0"?>
<Bottles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <MainTitle>MainTitle</MainTitle>
  <Bottleset>
    <Bottle>
      <Title>Title1</Title>
      <PhotoFileName>PhotoFileName1</PhotoFileName>
    </Bottle>
    <Bottle>
      <Title>Title2</Title>
      <PhotoFileName>PhotoFileName2</PhotoFileName>
    </Bottle>
  </Bottleset>
</Bottles>
然后我创建了一个 WP 应用程序,并引用了BusinessLogic.dll项目库。
在 MainPage.xaml 文件中,我放置了 XML 命名空间声明
xmlns:businesslogic="clr-namespace:BusinessLogic;assembly=BusinessLogic"
然后我在 MainPage.xaml Resources 集合中实例化了BottlesPresenter类
<phone:PhoneApplicationPage.Resources>
    <businesslogic:BottlesPresenter x:Key="bottlesPresenter" />        
</phone:PhoneApplicationPage.Resources>
最后在内容区域中放置一个 TextBlock 并绑定到该资源:
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <TextBlock HorizontalAlignment="Center"
         VerticalAlignment="Center"
         Text="{Binding Source={StaticResource bottlesPresenter},
                                  Path=Bottles.MainTitle}" />
不幸的是,我启动了调试器,打开了模拟器,到达了启动画面并且没有继续。
简而言之:我无法创建BottlesPresenter类的实例。
我把头撞在墙上好几个星期都没有找到解决办法。
请问有人可以帮我吗?
非常感谢
安东尼奥