我想用一个例子描述问题:
我所知道的: - 通过c#
添加HubSectionmyhubtest.cs
HubSection hubSection = new HubSection();
hubSection.Header = "My Title";
...
this.MyHub.Sections.Add(hubSection);
myhubtest.xaml:
<Hub x:Name="MyHub" SectionHeaderClick="Hub_SectionHeaderClick">
...
通过c#添加DataTemplate myhubtest.cs
对象xHubListTemplate; this.Resources.TryGetValue(&#34; xHubListTemplate&#34;,out xHubListTemplate); DataTemplate xHubListDataTemplate = xHubListTemplate as DataTemplate; hubSection.ContentTemplate = xHubListTemplate as DataTemplate;
的App.xaml
<DataTemplate x:Key="xHubListTemplate">
<ListView x:Name="xHubListView" IsItemClickEnabled="True"
Margin="0,0,0,0"
...
</ListView>
</DataTemplate>
如何分配ItemsSource和ItemsTemplate以及ItemClick?
答案 0 :(得分:0)
<Page.Resources>
<CollectionViewSource x:Name="cvsData"/>
</Page.Resources>
<DataTemplate x:Key="xHubListTemplate">
<ListView x:Name="xHubListView" ItemsSource="{Binding Source={StaticResource cvsData}}" IsItemClickEnabled="True" ItemClick="xHubListView_ItemClick" >
</ListView>
</DataTemplate>
代码:
private bool LoadData()
{
this.cvsData.Source = ...... (list of data)
}
private void xHubListView_ItemClick(object sender, ItemCLickEventArgs e)
{
}