2013-04-03 49 views
4

我使用Blend for VS 2012來創建WP7.8應用程序的模板。有一些示例數據(位於單獨的xaml文件中,請參見下方),這些數據在Silverlight頁面上以設計模式正確顯示。更改此數據(使用名稱空間和類名稱)會導致編輯器錯誤,並且新數據不再在設計模式中顯示。 (List組件被示出爲空)設計時錯誤(未找到可附加屬性x)

頁面的主要XAML文件是以下

<phone:PhoneApplicationPage 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800" 
    x:Class="DesignSketch.MainPage" 
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="Portrait" Orientation="Portrait" 
    shell:SystemTray.IsVisible="True"> 

    <!--LayoutRoot is the root grid where all page content is placed--> 
    <Grid x:Name="LayoutRoot" Background="Transparent"> 
     <!--Pivot Control--> 
     <controls:Pivot Title="Application"> 
      <!--Pivot item one--> 
      <controls:PivotItem Header="List"> 
       <!--Double line list with text wrapping--> 
       <ListBox x:Name="FirstListBox" ItemsSource="{Binding Items}" Margin="0,0,-12,0"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Margin="0,0,0,17" Width="432" Height="78"> 
           <TextBlock Text="{Binding Sum}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
           <TextBlock Text="{Binding Description}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
          </StackPanel> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
      </controls:PivotItem> 


     </controls:Pivot> 
    </Grid> 
</phone:PhoneApplicationPage> 

如可以看到的,它使用

d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}" 

設計模式綁定。 Howerever錯誤(提示)被示出「在MainViewModelSampleData.xaml發現錯誤」

在此XAML的內容是

<viewModels2:ExpensesPageVM 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:viewModels2="clr-namespace:DesignSketch" 
    > 
    <viewModels2:ExpensesPageVM.Items> 
      <viewModels2:Expense Sum="10" Description="Fee1" /> 
      <viewModels2:Expense Sum="600" Description="Fee2" /> 
    </viewModels2:ExpensesPageVM.Items> 

</viewModels2:ExpensesPageVM> 

它以下提示的誤差一起表示
的可連接性在類型ExpensesPageVM中找不到項目

找不到類型viewModels2:Expense。驗證你是不是缺少程序集引用和引用的所有組件已經被內置

的類ExpensesPageVM和費用都位於DesignSke​​tch命名空間,有以下代碼:

using System; 
using System.Linq; 
using System.ComponentModel; 
using System.Collections.ObjectModel; 

namespace DesignSketch 
{ 
    public class ExpensesPageVM : INotifyPropertyChanged 
    { 
     public ExpensesPageVM() 
     { 
      this.Items = new ObservableCollection<Expense>(); 
     } 

     /// <summary> 
     /// A collection for ItemViewModel objects. 
     /// </summary> 
     public ObservableCollection<Expense> Items { get; set; } 

     private string _sampleProperty = "Sample Runtime Property Value"; 
     /// <summary> 
     /// Sample ViewModel property; this property is used in the view to display its value using a Binding 
     /// </summary> 
     /// <returns></returns> 
     public string SampleProperty 
     { 
      get 
      { 
       return _sampleProperty; 
      } 
      set 
      { 
       _sampleProperty = value; 
       NotifyPropertyChanged("SampleProperty"); 
      } 
     } 

     public bool IsDataLoaded 
     { 
      get; 
      private set; 
     } 

     /// <summary> 
     /// load initial data from sdf 
     /// </summary> 
     public void LoadData() 
     { 
      //... 
     } 

     public event PropertyChangedEventHandler PropertyChanged; 
     private void NotifyPropertyChanged(String propertyName) 
     { 
      if (null != PropertyChanged) 
      { 
       PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
      } 
     } 
    } 
} 

其他文件

using System; 
using System.Data.Linq.Mapping; 
using System.ComponentModel; 

namespace DesignSketch 
{ 
    [Table] 
    public class Expense: INotifyPropertyChanged, INotifyPropertyChanging 
    { 
     private int expenseID; 

     [Column(IsPrimaryKey = true, 
      IsDbGenerated = true, 
      DbType="INT NOT NULL Identity", 
      CanBeNull=false, 
      AutoSync=AutoSync.OnInsert)] 
     public int ExpenseID { get {return expenseID;} 
      set 
      { 
       if (expenseID == value) return; 
       NotifyPropertyChanging("ExpenseID"); 
       expenseID = value; 
       NotifyPropertyChanged("ExpenseID"); 
      } 
     } 

     private string description { get; set; } 

     [Column] 
     public string Description { get { return description; } 
      set 
      { 
       if (description == value) return; 

       NotifyPropertyChanging("Description"); 
       description = value; 
       NotifyPropertyChanged("Description"); 
      } 
     } 

     private decimal sum; 

     [Column] 
     public decimal Sum 
     { 
      get { return sum; } 
      set 
      { 
       if (sum == value) return; 

       NotifyPropertyChanging("Sum"); 
       sum = value; 
       NotifyPropertyChanged("Sum"); 

      } 
     } 

     private DateTime date; 

     [Column] 
     public DateTime Date { get { return date; } 
      set 
      { 
       if (date == value) return; 

       NotifyPropertyChanging("Date"); 
       date = value; 
       NotifyPropertyChanged("Date"); 
      } 
     } 

     public event PropertyChangedEventHandler PropertyChanged; 

     private void NotifyPropertyChanged(string propertyName) 
     { 
      if (PropertyChanged != null) 
      { 
       PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
      } 
     } 

     public event PropertyChangingEventHandler PropertyChanging; 

     private void NotifyPropertyChanging(string propertyName) 
     { 
      if (PropertyChanging != null) 
      { 
       PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); 
      } 
     } 
    } 
} 

費用自定義爲存儲在手機的本地數據庫中。

我實際上有相同的代碼工作(由Blend生成),其中樣本數據在設計時間內完美顯示。有人知道爲什麼它不是這個代碼嗎?

+0

是MainViewModelSampleData和ExpensesPageVM在同一個項目? – termit

回答

1

如果DesignSke​​tch是不是在目前的組裝,那麼這行

xmlns:viewModels2="clr-namespace:DesignSketch" 

改變

xmlns:viewModels2="clr-namespace:DesignSketch;assembly=NameOfAssemblyThatHoldsDesignSketch" 
相關問題