0
我有下面的XAML代码:你能数据绑定列表框与一个IEnumerable <type>
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="OrganisationTemplate">
<Grid Margin="40,0,0,0">
<StackPanel>
<TextBlock Text="{Binding name}"></TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<phone:PanoramaItem Header="Organisations">
<ListBox Name="Organisation" ItemTemplate="{StaticResource OrganisationTemplate}" DataContext="{Binding Organisations, Mode=OneWay}" Margin="0,0,0,96"/>
</phone:PanoramaItem>
,我想知道,如果结合“企业”必须是一个列表或ICollection的或东西...或者它可以是一个IEnumerable。这只是它目前不工作。
class DashboardViewModel
{
private OrganisationRepository organisationRepository { get; set; }
public IEnumerable<Organisation> Organisations { get; set; }
public DashboardViewModel()
{
LoadOrganisationSection();
}
private async void LoadOrganisationSection()
{
organisationRepository = new OrganisationRepository();
Organisations = await organisationRepository.GetAll();
OnPropertyChanged("Organisations");
//LoadBar loadBar = new LoadBar("Logging in");
//loadBar.ShowLoadBar(this);
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler tempEvent = PropertyChanged;
if (tempEvent != null)
{
// property changed
tempEvent(this, new PropertyChangedEventArgs(propertyName));
}
}
}
编辑:: //
public IEnumerable<Organisation> Organisations
{
get
{
return new Organisation[] { new Organisation { name = "hi" } };
}
set
{
OnPropertyChanged();
}
}
如果我这样做,我得到的东西回来了,所以它是不工作的触发器。任何想法我如何做到这一点?当我在organisationRepository.GetAll()完成时候等待。我需要onchange来发生和更新。 doh
啊,我会给它一个尝试队友!现在感谢(必须等到我回家的时候) – Jimmyt1988
ItemsSource =“{Binding Organizations,Mode = OneWay}”不起作用。卫生署。但我认为永恒的不是问题 – Jimmyt1988
我在做财产改变了事情不正确? – Jimmyt1988