使用Silverlight 4/MVVM。Silverlight MVVM綁定列表框
我想將ViewModel綁定到帶有自定義模板的列表框,但數據不顯示。如果設置了DisplayMemberPath屬性,我已經設法獲取原始數據。如果我刪除此屬性並嘗試綁定到文本塊,則不顯示任何內容。這裏是XAML
<ListBox Height='200'
HorizontalAlignment='Left'
Margin='10,10,0,0'
Name='lstForumTopics'
VerticalAlignment='Top'
Width='200'
DataContext='{Binding Path=ForumTopics,Source={StaticResource ForumViewModel}}'
ItemsSource='{Binding Path=ForumTopics,Source={StaticResource ForumViewModel}}'>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation='Vertical'>
<TextBlock Text='{Binding ForumTopicText,Source={StaticResource ForumViewModel}}'></TextBlock>
<TextBlock Text='{Binding PostCount,Source={StaticResource ForumViewModel}}'></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Background>
<LinearGradientBrush EndPoint='0.5,1'
StartPoint='0.5,0'>
<GradientStop Color='#FFDCE2E5'
Offset='1' />
<GradientStop Color='White'
Offset='0' />
</LinearGradientBrush>
</ListBox.Background>
</ListBox>
我已經解決了這個問題 - 這是文本塊的綁定語法 – Greg 2010-12-15 14:25:03