C# LongListSelector未绑定数据数组Windows Phone 8
我正在使用LongListSelector并尝试绑定数组。但没有显示任何数据。以下是我的代码,请让我知道我做错了什么 XAMLC# LongListSelector未绑定数据数组Windows Phone 8,c#,wpf,xaml,data-binding,windows-phone-8,C#,Wpf,Xaml,Data Binding,Windows Phone 8,我正在使用LongListSelector并尝试绑定数组。但没有显示任何数据。以下是我的代码,请让我知道我做错了什么 XAML 在类中有一些属性,在xaml中有不同的绑定 <phone:LongListSelector Name="peopleLongListSelector" ItemsSource="{Binding ComponentData}"
在类中有一些属性,在xaml中有不同的绑定
<phone:LongListSelector Name="peopleLongListSelector"
ItemsSource="{Binding ComponentData}"
GroupHeaderTemplate="{StaticResource LongListSelectorGroupHeaderTemmplate}"
ItemTemplate="{StaticResource LongListSelectorItemTemplate}"
HideEmptyGroups ="true"
IsGroupingEnabled ="true"
LayoutMode="List">
</phone:LongListSelector>
<DataTemplate x:Key="LongListSelectorGroupHeaderTemmplate">
<Border Background="Transparent" Padding="5">
<Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2"
Width="62" Height="62" Margin="0,0,18,0"
HorizontalAlignment="Left">
<TextBlock Text="{Binding Name}"
Foreground="{StaticResource PhoneForegroundBrush}"
FontSize="48"
Padding="6"
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
</Border>
</Border>
</DataTemplate>
<DataTemplate x:Key="LongListSelectorItemTemplate">
<StackPanel Orientation="Horizontal" Margin="4,4">
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Subtitle}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Date}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</DataTemplate>
在Listview LongListSelectorGroupHeaderTemplate中,我是组件类的绑定名称属性。即使是这样,也没有被绑定。。。??你有没有在一个示例应用程序中试用过它?你有项目吗?我有项目和多个组件。你试过这个密码了吗。这对您有用吗?您正在异步获取数据-我猜您的LLS没有更新-您有绑定,但没有INotifyPropertyChanged。尝试实现该接口并在PropertyChanged上运行。或者可能使用ObservableCollection而不是ComponentData数组。
public class Component
{
public string Guid {get; set;}
public string Name{get; set;}
public Item[] Items{get; set;}
}
public class Item
{
public string Title{get; set;}
public string Subtitle{get; set;}
public string Date{get; set;}
}
public class MainLstViewModel : BaseViewModel
{
private Component[] ComponentData;
public MainLstViewModel()
{
ComponentData = Proxy.GetDataAsync();
}
}
<phone:LongListSelector Name="peopleLongListSelector"
ItemsSource="{Binding ComponentData}"
GroupHeaderTemplate="{StaticResource LongListSelectorGroupHeaderTemmplate}"
ItemTemplate="{StaticResource LongListSelectorItemTemplate}"
HideEmptyGroups ="true"
IsGroupingEnabled ="true"
LayoutMode="List">
</phone:LongListSelector>
<DataTemplate x:Key="LongListSelectorGroupHeaderTemmplate">
<Border Background="Transparent" Padding="5">
<Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2"
Width="62" Height="62" Margin="0,0,18,0"
HorizontalAlignment="Left">
<TextBlock Text="{Binding Name}"
Foreground="{StaticResource PhoneForegroundBrush}"
FontSize="48"
Padding="6"
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
</Border>
</Border>
</DataTemplate>
<DataTemplate x:Key="LongListSelectorItemTemplate">
<StackPanel Orientation="Horizontal" Margin="4,4">
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Subtitle}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Date}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</DataTemplate>