I used Blend for VS 2012 to create a WP7.8 application template. There were some sample data (placed in a separate xaml file, see below) that was shown correctly in design mode on the silverlight page. Changing this data (with class names and names) leads to editor errors, and new data is no longer displayed in design mode. (the List component is displayed as empty)
The main page xaml file is
<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"> <Grid x:Name="LayoutRoot" Background="Transparent"> <controls:Pivot Title="Application"> <controls:PivotItem Header="List"> <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>
apparently he uses
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
to bind design mode. Howverver error (tooltip) shows "Errors found in MainViewModelSampleData.xaml"
the contents of this 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>
the following prompt errors are shown for it
Attached Property Items were not found in type ExpensesPageVM
Type viewModels2: Expense not found. Make sure you donโt have a reference to the assembly and that all reference assemblies are built
The ExpensesPageVM and Expense classes are located in the DesignSketch namespace and have the following code:
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>(); }
another file
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)); } } } }
The expense is configured for storage in the local database of the phone.
I have almost the same code that works (generated by Blend), where the data samples are displayed perfectly during development. Does anyone know why this is not with this code?