没有反映我有一个视图模型,我设定它DataContext.In XAML实例我已经绑定列表框的ItemSource到ViewModel.But可观察集合,当我运行的程序没有出现在列表框中。可能是什么原因。设置到的DataContext在列表框
我ViewModel类:
public class ViewModel
{
public ObservableCollection<Data> _collectionData = new ObservableCollection<Data>();
-----
-----
}
的XAML:
主网页ListBox Name="myListBox" Margin="8,113,8,8" ItemsSource="{Binding _collectionData}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Border BorderThickness="3" BorderBrush="#A5FFFFFF" Width="80" Margin="0,20,0,20" Height="60">
<Image Source="{Binding ImageUrl, Mode=OneWay}" VerticalAlignment="Stretch" Margin="0,0,0,0" Width="80" Height="60" Stretch="Fill" />
</Border>
<TextBlock TextWrapping="Wrap" Text="{Binding Title}" FontSize="40" FontWeight="Normal" VerticalAlignment="Center" Margin="30,0,0,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
构造:
ViewModel vm = new ViewModel();
this.DataContext = vm;
但是,当我给myListBox.ItemsSource = vm._collectionSplashData;
它的工作原理。什么可能是什么原因?
你尝试让属性,而不是场? – 2011-03-18 07:38:21
@ArsenMkrt非常感谢。曾经工作过。你救了我的一天:)但是你有任何想法为什么公共领域不工作? – Vaysage 2011-03-18 07:46:43
不客气,我现在把它发布为答案 – 2011-03-18 07:52:30