It would be really useful if you could see all binded data in design time in VisualStudio or Blend.
To do this you should set page DataContext in xaml:
<Page.DataContext>
<viewModels:MainPageViewModel />
</Page.DataContext>
In this case you will use the same ViewModel for design and run time. If ViewModel require different data loading logic for design and run time you should use Windows.ApplicationModel.DesignMode.DesignModeEnabled in ViewModel constructor to determine in witch mode ViewModel is loading. For example:
if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
//Load data from run time
}
else
{
//Load data from design time
}
If you want you can set different ViewModel for design time. To do this set d:Page.DataContext in xaml:
<d:Page.DataContext>
<viewModels:DesignTimeMainPageViewModel />
</d:Page.DataContext>
All bindings work fine in design time, except binding to static CollectionViewSource:
<Page.Resources>
<CollectionViewSource
x:Name="Balance"
IsSourceGrouped="true"
ItemsPath="Accounts"
d:DesignSource="{Binding BalanceList}"
Source="{Binding BalanceList}" />
</Page.Resources>
<Grid>
<ListView ItemsSource="{Binding Source={StaticResource Balance}}" />
</Grid>
To display data in ListView that binded through CollectionViewSource in design time I've moved CollectionViewSource instance to ViewModel layer.
private CollectionViewSource balance;
public ICollectionView Balance
{
get
{
if (balance == null)
{
balance = new CollectionViewSource();
balance.IsSourceGrouped = true;
balance.ItemsPath = new Windows.UI.Xaml.PropertyPath("Accounts");
Binding binding = new Binding();
binding.Source = BalanceList;
BindingOperations.SetBinding(balance, CollectionViewSource.SourceProperty, binding);
}
return balance.View;
}
set
{
}
}
Every time when I reset BalanceList source collection, I call OnPropertyChanged("Balance"); to update binding.