我有以下 xaml:
<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();
}
}
如果我这样做,我会得到一些东西,所以触发器不起作用。有什么想法我该怎么做吗?当我对 organizationRepository.GetAll() 的等待完成时。我需要 onchange 发生并更新。多哈