シンプルなウィンドウフォン7ページを作成しています。私は(MVVMライトを使用して)MVVMを実行し、List<Category>
typeプロパティをにバインドしていListPicker
ます。AddExpenseViewModel
このプロパティは、以下のような名前のビューモデルで定義されます
public class AddExpenseViewModel:ViewModelBase
{
public List<Category> Categories
{
get { return categories; }
set
{
categories = value;
RaisePropertyChanged("Categories");
}
}
}
Category
クラスは次のように定義されます
public class Category
{
public string Name { get; set; }
}
XAMLでは、最初にリソースを次のように定義します
<UserControl.Resources>
<bs:ViewModelLocator x:Key="ViewModelLocator" />
</UserControl.Resources>
次に、DataContext
を含むグリッドのListPicker
を設定します
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="13,1,11,-1"
DataContext="{Binding Path=AddExpenseViewModel,
Source={StaticResource ViewModelLocator}}">
そしてこれが私のXAMLですListPicker
<toolkit:ListPicker
HorizontalAlignment="Left"
Height="50"
Width="200"
Grid.Row="2"
Grid.Column="1"
DataContext="{Binding AddExpenseViewModel}"
ItemsSource="{Binding Path=Categories, Mode=OneWay}" >
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border Background="LightGreen" Width="*" Height="*">
<TextBlock Text="{Binding Name}"></TextBlock>
</Border>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
</toolkit:ListPicker>`
これは動作しません。はListPicker
常に空です。私はここで何か間違ったことをしていますか?